After upgrading Gradle to 5.1.1, I found that I\'m unable to add bundleReleaseAar
as an artifact to my MavenPublication. Here\'s the relevant snippet of my buil
I solved it by calling the artifact function into the afterEvaluate closure, the issue is that the artifact function does not handle all the configuration lazily
publishing {
publications {
aar(MavenPublication) {
groupId libraryGroupId
version libraryVersion
artifactId libraryArtifactId
afterEvaluate {
artifact bundleReleaseAar
//artifact sourcesJar
//artifact packageJavadoc
}
}
}
}
Reference https://github.com/moberwasserlechner/capacitor-oauth2/issues/10
Short Answer :
You need to enclose the publishing {} block inside a project.afterEvaluate as follows:
project.afterEvaluate {
publishing {
publications {
aar(MavenPublication) {
groupId libraryGroupId
version libraryVersion
artifactId libraryArtifactId
artifact bundleReleaseAar
//artifact sourcesJar
//artifact packageJavadoc
}
}
}
}
Long Answer :
Prior to gradle version 4.8, publishing block was implicitly treated as if all the logic inside it was executed after the project was evaluated. This was only block that behaved this way and this behavior was discontinued post gradle version 4.8 for consistency's sake. bundleReleaseAar task seems to be available only after project evaluation is complete and therefore to maintain behavior it must be explicitly enclosed inside project.afterEvaluate{}
Reference : https://docs.gradle.org/current/userguide/upgrading_version_4.html#rel4.8:deferred_configuration
I fix this problem change artifact from:
artifact bundleReleaseAar
to:
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
this help me Gradle sync success, but i must call assembleRelease directly, before ./gradlew publish