I have been given the following gradle code to publish a library on JitPack.io:
apply plugin: 'maven-publish'
def getGroupId = { ->
return "com.packagename"
}
def getArtificatId = { ->
return "ArtifactId"
}
def getVersionName = { ->
return "0.0.1"
}
publishing {
publications {
LibraryName(MavenPublication) {
groupId getGroupId()
artifactId getArtificatId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtifactId()}.aar")
pom.withXml {
// add dependencies to pom
def dependencies = asNode().appendNode("dependencies")
configurations.implementation.allDependencies.each {
if (it.group != null &&
"unspecified" != it.name &&
it.version != null) {
def dependencyNode = dependencies.appendNode("dependency")
dependencyNode.appendNode("groupId", it.group)
dependencyNode.appendNode("artifactId", it.name)
dependencyNode.appendNode("version", it.version)
}
}
}
}
}
repositories {
maven {
}
}
}
But it is consistently failing, giving this error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':LibraryName:publishLibraryNamePublicationToMavenLocal' (type 'PublishToMavenLocal').
- Gradle detected a problem with the following location: '/home/jitpack/build/LibraryName/build/outputs/aar/LibraryName-release.aar'.
Reason: Task ':LibraryName:publishLibraryNamePublicationToMavenLocal' uses this output of task ':LibraryName:bundleReleaseAar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Possible solutions:
1. Declare task ':LibraryName:bundleReleaseAar' as an input of ':LibraryName:publishLibraryNamePublicationToMavenLocal'.
2. Declare an explicit dependency on ':LibraryName:bundleReleaseAar' from ':LibraryName:publishLibraryNamePublicationToMavenLocal' using Task#dependsOn.
3. Declare an explicit dependency on ':LibraryName:bundleReleaseAar' from ':LibraryName:publishLibraryNamePublicationToMavenLocal' using Task#mustRunAfter.
Please refer to https://docs.gradle.org/8.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 42s
I have tried all the
tasks.named('publishLibraryNamePublicationToMavenLocal') {
mustRunAfter tasks.named('bundleReleaseAar')
}
kind of solutions provided by different search results and ChatGPT and Bard but it still doesn't work.
Any idea what am I doing wrong? I have been told that exactly this piece of code was working previously, like 2 months ago.