Java – use gradle to upload the source to the nexus repository
I successfully uploaded my jars to a nexus repository, which uses the Maven plug-in for gradients, but did not upload the source code This is my configuration:
uploadArchives {
repositories{
mavenDeployer {
repository(url: "http://...") {
authentication(userName: "user",password: "myPassword")
}
}
}
}
I searched and found that I can add a source by adding a new task
task sourcesJar(type: Jar,dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
This is good, but I think there must be a better solution for configuring Maven plug-in, such as uploadsource = true:
uploadArchives {
repositories{
mavenDeployer {
repository(url: "http://...") {
authentication(userName: "user",password: "myPassword")
}
uploadSources = true
}
}
}
Solution
There is no better solution than your own description The gradle Maven plugin is uploading all artifacts generated in the current project This is why you must explicitly create a "source" artifact
When using the new Maven publish plug-in, the situation will not change Here, you also need to explicitly define other artifacts:
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
}
The reason is that graduates are more general construction tools than pure Java projects
