Hi everyone,
I was trying to publish a gradle project to our private Sonatype Nexus repo using the maven-publish plugin. I followed the example “Example of publishing a java module with a source artifact and custom POM description” on this page:
https://docs.gradle.org/current/javadoc/org/gradle/api/publish/maven/MavenPublication.html
apply plugin: "java"
apply plugin: "maven-publish"
group = 'com.mywebsite'
version = '1.3-SNAPSHOT'
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
myPublication(MavenPublication) {
from components.java
artifact(sourceJar) {
classifier "sources"
}
pom.withXml {
asNode().appendNode('description', 'A demonstration of Maven POM customization')
}
}
}
}
As a result, artifacts: “myproject-1.3-SNAPSHOT-sources.jar”, “myproject-1.3-SNAPSHOT.jar”, got published to nexus(can be reproduced on local .m2/repository), but they are identical(checked with md5 hash), and when unpacking, they have *.java file in there instead of expected *.class files.
Then I tried the following code, modified from this page:
apply plugin: "java"
apply plugin: "maven-publish"
group = 'com.mywebsite'
version = '1.3-SNAPSHOT'
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
myPublication(MavenPublication) {
from project.components.java
artifact sourceJar {
classifier "sources"
}
pom.withXml {
asNode().appendNode('description', 'A demonstration of Maven POM customization')
}
}
}
}
It worked as expected, artifacts: “myproject-1.3-SNAPSHOT-sources.jar”, “myproject-1.3-SNAPSHOT.jar”, got published, and when unpacking them, the first one has *.java file in there and the second one has *.class files in there.
The only difference I noticed between these two block of code is:
artifact(sourceJar)
vs
artifact sourceJar
I don’t have enough knowledge about gradle to tell why replacing the parenthesis with empty space made such difference, but since the example in the doc doesn’t work, I think it probably need some revision? I’d be very glad to know why parenthesis made this difference. But I could be wrong, please let me know if I missed something here.
Thanks!
PS: this is the output of gradle --version:
------------------------------------------------------------
Gradle 2.6
------------------------------------------------------------
Build time: 2015-08-10 13:15:06 UTC
Build number: none
Revision: 233bbf8e47c82f72cb898b3e0a96b85d0aad166e
Groovy: 2.3.10
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_51 (Oracle Corporation 25.51-b03)
OS: Mac OS X 10.10.4 x86_64