Moving to Gradle 6 I wanted to use the new methods for adding sources and javadoc.
This:
java {
withJavadocJar()
withSourcesJar()
}
Instead of this:
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives jar
archives sourcesJar
archives javadocJar
}
However this does not work.
* What went wrong:
Execution failed for task ':publishApiPublicationToMavenRepository'.
> Failed to publish publication 'api' to repository 'maven'
> Invalid publication 'api': multiple artifacts with the identical extension and classifier ('jar', 'javadoc').
The publication configuration of my API project
publishing {
repositories {
maven {
url buildRelease ? releasesRepoUrl : snapshotsRepoUrl
credentials {
username = nexusUsername
password = nexusPassword
}
}
}
publications {
api(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
}
}
}
Not sure if I am missing something? I found some suggestions that I should use different publications, but I am not sure what is the “correct” way of doing it?
publications {
api(MavenPublication) {
from components.java
}
sources(MavenPublication) {
artifact sourcesJar
}
javadoc(MavenPublication) {
artifact javadocJar
}
}
I managed to get it working by removing artifact sourcesJar
and artifact javadocJar
from the publications. These was uploaded to the repository even if not specified within publications.