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?
MavenPublication A MavenPublication is the representation/configuration of how Gradle should publish something in Maven format. You directly add a named Maven Publication the project's publishing.publications container by providing MavenPublication as the type.
For any individual MavenPublication, only a single component can be provided in this way. The following example demonstrates how to publish the 'java' component to a Maven repository.
* What went wrong: A problem occurred configuring project ':test-java-multiproject-api'. > Could not get unknown property 'components' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication. As far as I know, both situations should be roughly the same.
Each supplied source is interpreted as per MavenPublication.artifact (java.lang.Object) . For example, to exclude the dependencies declared by a component and instead use a custom set of artifacts: Silences all the compatibility warnings for the Maven publication.
I came across this after updating AGP for Jitpack. Both the MavenPublication block and the components.release
line appear to use your build variant name. So if you have a standard debug and release variant it would look like this:
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = 'com.my.group'
artifactId = 'id'
version = Config.libraryVersion
}
}
}
But if you have a build variant with a name other than release, you need to use that:
afterEvaluate {
publishing {
publications {
productionRelease(MavenPublication) {
from components.productionRelease
groupId = 'com.my.group'
artifactId = 'id'
version = Config.libraryVersion
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With