To use maven plugin or maven-publish plugin to publish artifacts to Nexus Maven Repository.
We are using Nexus 3 as Repository Manager to publish to either releases or snapshots repositories.
A similar topic has previously discussed the same, but for Artifactory and not properly concluded.
I wanted to use the new maven-publish for the reason that maven plugin might one day be gone/deprecated. However the maven-publish has been incubation forever and does not seem quite feature complete, yet.
The maven-publish lacks the ability to distinguish between releases and snapshots like maven plugin does.
Also the maven-publish plugin has a more lines of code than using the maven plugin, requiring publications.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier 'sources'
from sourceSets.main.allJava
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
Using the maven plugin to publish the artifacts:
uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://nexus.company.com:8443/repository/releases") {
authentication(userName: "deployment", password: "password")
}
snapshotRepository(url: "https://nexus.company.com:8443/repository/snapshots") {
authentication(userName: "deployment", password: "password")
}
}
}
}
Using maven-publish plugin to publish the artifacts.
The only solution I have found to publish to either releases or snapshots is checking the version for a snapshot to determine the repository URL.
publishing {
repositories {
maven {
url 'https://nexus.company.com:8443/repository/' + publishUrl
credentials {
username = 'deployment'
password = 'password'
}
}
}
publications {
api(MavenPublication) {
from components.java
artifact sourcesJar {
classifier "sources"
}
artifact javadocJar {
classifier "javadoc"
}
}
}
}