I'm deploying a library to the MavenCentral for couple of years. The latest update to the AGP 8.1.0 broke the process, resulting in error:
Failed to publish publication 'release' to repository 'mavenLocal'
Invalid publication 'release': multiple artifacts with the identical extension and classifier ('jar.asc', 'sources'). `
As far as I got it the new AGP for some reason adds unobfuscated 'sources.jar' and it collides with mine (the old one)
My code (relevant parts) is:
tasks.register('androidSourcesJar', Jar) {
archiveClassifier.set('sources')
// some more code
}
then in publication itself:
// Applies the component for the envProdRelease build variant.
from components.envProdRelease
// Add the sources and Javadoc JARs to the publication
artifact androidSourcesJar // <- this causing the error
If I revert AGP to the version 7.4.2 everything works as expected.
If i remove the artifact androidSourcesJar
from the publication the script will publish the library with non-obfuscated sources which is totally not acceptable for me.
I'm using 'maven-publish'
plugin and nexus-publish-plugin
.
After many hours I've found a simple solution to the problem. All you need to do is force the maven-publish plugin NOT to create sources.jar. For this purpose you need to modify the component that MavenPublication takes (unless you want to create your own set of Gradle tasks), so the solution for my problem was:
android{
publishing {
//note the variant name should be equal to the one that Maven takes
singleVariant("envProdRelease") {
// if you don't want sources/javadoc, comment out these lines
//withSourcesJar()
//withJavadocJar()
}
}
}
Now you can create sources.jar and/or javadoc.jar with your own task.