I have an Android project with multiple modules and I want to publish them to self-hosted maven repo. I earlier had the publishing code present in individual modules and things worked just fine. I am now trying to move the publishing code into the project build.gradle
so that I can reuse the code. The code inside my individual modules was:
afterEvaluate {
// To avoid publishing the applications inside the project...
if (!plugins.hasPlugin("android")) {
publishing {
publications {
mavenAar(MavenPublication) {
artifactId "$project.name"
from components.release
}
}
repositories {
.... My repo details and credentials .......
}
}
}
}
and things worked just fine. When I moved the code to the project build.gradle
, like this:
subprojects {
apply plugin: 'maven-publish'
afterEvaluate {
// To avoid publishing of the applications inside the project ..
if (!plugins.hasPlugin("android")) {
publishing {
publications {
mavenAar(MavenPublication) {
artifactId "$project.name"
from components.release
}
}
repositories {
.... My reop details and creddentials .....
}
}
}
}
}
I started getting the following error when running the publish
task:
A problem occurred configuring project ':mymodule'.
> Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
Can someone point out the problem here?
Make sure that you are using
com.android.tools.build:gradle:4.1.2
or above version 3.6 in bothroot/build.gradle
androot/<library_name>/build.gradle
. Then make sure both plugins were declared inroot/<library_name>/build.gradle
like this:then you can use components.release
You can read this docs https://developer.android.com/studio/build/maven-publish-plugin#groovy for more information