Issue
I'd like to upload my jar to the Maven Central repository using gradle uploadArchives
and use it in other projects as a dependency.
I've followed this nice tutorial with the result that my jars are uploaded to Sonatype Nexus (see screenshot below).
The 0.1 version of my jar is available; the line
dependencies {compile 'eu.matthiasbraun:Utils:0.1'}
works just fine in the build.gradle
file of my dependent project. I released the 0.1 version by clicking the Close and the Release buttons seen in the screenshot. After that I commented on the Jira ticket I had created here and was told that central sync would run every two hours.
It was my understanding that if I now wanted to release the 0.2 version of my jar, I simply would do gradle uploadArchives
and change the line in build.gradle` of my dependent project to
dependencies {compile 'eu.matthiasbraun:Utils:0.2'}
.
Yet, when I gradle build
my dependent project (after two hours) I got the error that the dependency could not be resolved.
Here's my complete build.gradle
which uploads my jar to Sonatype Nexus: link.
How can I automate the release of jars to Maven Central using Gradle?
Solution
I've used the nexus-workflow gradle plugin to automate the releasing of repositories.
I put this at the top of the build.gradle
of my project I want to release:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.adaptc.gradle:nexus-workflow:0.6'
}
}
apply plugin: 'nexus-workflow'
Additionally I put these three properties in ~/.gradle/gradle.properties
oss-releases.username=mySonatypeUsername
oss-releases.password=mySonatypePassword
oss-releases.url=https://oss.sonatype.org/index.html#stagingRepositories
When I want to push a release to Maven Central, I first upload the jars to Nexus using gradle uploadArchives
and then I do gradle nexusStagingRelease
. This closes and releases all my open repos on Nexus.
Edit: I also found this plugin by Benjamin Muschko which seems to be an alternative to the plugin described above. I didn't try it yet, though.
Answered By - Matthias Braun