Simplified Releases to the Central Repository with Nexus

September 30, 2013 By Manfred Moser

4 minute read time

The Central Repository continues to be the largest repository of binary components for Java developers and beyond. A majority of open source projects including organizations such as Apache Software Foundation, Google , Github and many more take advantage of the free hosting via the Sonatype Open Source Software Repository Hosting OSSRH. The release automation for all these projects is automated using the Nexus staging suite as input funnel and if you are running Nexus Pro, you can take advantage of the same features in your own organization.

The Nexus staging suite is used to separate deployment rights, automate the validation of the deployment components as well as allow multi-staged release validation steps including abandoning a release. In this post I am going to show you how you can simplify this process for your project and do a full release on the command line.

In order to showcase the complete flow I have finally released an open source project of mine in version 1.0.0 and will go through all the steps I followed with you. The project Progressive Organization POM implements a comprehensive Maven parent POM progressively selecting the latests versions of all referenced Maven plugins. Such an organization POM is a well known best practice for Maven usage and you are free to use my project to save you from the effort.

In order to release the 1.0.0 version, I first updated a few more plugins by checking what is available with:

<code>mvn versions:display-plugin-updates</code>

After some updates and a build, to check all is well, with:

<code>mvn clean install</code>

I started the release process using the Maven Release Plugin:

<code>mvn release:prepare</code>

As you can see in the log , I provided details for the version and tag. The release plugin then went ahead and did the necessary changes to the pom.xml file and the git commits. With this preparation done I was ready to do the actual release with:

<code>mvn release:perform</code>

If you look at the log, you can see that a local checkout of the 1.0.0 tag was created into target/checkout and then a deployment build is performed automatically. This deployment does not use the maven-deploy-plugin, since I have configured the nexus-staging-maven-plugin.

<code>&lt;plugins&gt;
  &lt;plugin&gt;
    &lt;groupId&gt;org.sonatype.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;nexus-staging-maven-plugin&lt;/artifactId&gt;
    &lt;extensions&gt;true&lt;/extensions&gt;
    &lt;inherited&gt;false&lt;/inherited&gt;
    &lt;configuration&gt;
      &lt;serverId&gt;ossrh-releases&lt;/serverId&gt;
      &lt;nexusUrl&gt;https://oss.sonatype.org/&lt;/nexusUrl&gt;
      &lt;stagingProfileId&gt;42b61fb4c62700&lt;/stagingProfileId&gt;
    &lt;/configuration&gt;
  &lt;/plugin&gt;
&lt;/plugins&gt;</code>

The above configuration is using an excplicit reference to the desired staging profile, which you can determine if you log into Nexus, select the desired staging profile and check the URL:

Staging Profile

The plugin performs a full local staging after a successful build, before uploading anything to the remote Nexus instance. This behaviour can be very useful for multi-module projects. Since staging is configured, it will upload into a staging repository and a whole number of rules will be vaildated. If you login to htts://oss.sonatype.org and have a look at the newly created staging repository, you can see a list of steps performed in the Activity panel:

The log as well as the image shows you that the nexus-staging-maven-plugin already closed the staging repository as well. With the maven-deploy-plugin you had to do this via the user interface and then also release via the user interface. With the staging plugin you can do it all on the command line.

If you examine the checkout in target/checkout you can see the files created as part of the local staging. It includes a properties file, that contains the name of the staging repository that was created among other things. You can see the full contents in another log I created. Thanks to this file you can finalize the release and the subsequent push of your components from Nexus to the Central Repository on the command line with:

<code>cd target/checkout
mvn nexus-staging:release</code>

and you will see something similar to my log. With this approach you can completely automate a release on a continuous integration server or at least run it all from the command line on your machine. And if you are not using Apache Maven, we also have Ant tasks that can be used by Ant or Gradle users or you can use the REST API in any scripting language. Oh and and by the way... we also offer training classes for Maven and Nexus ;-)

Tags: Nexus Repo Reel, Apache Maven, Nexus, Everything Open Source, Maven Release plugin, Central, Open Source, OSSRH

Written by Manfred Moser

Manfred is a former author, trainer, and community advocate at Sonatype. He speaks regularly at conferences such as JavaOne, OSCON, DevOpsDays. He is a long time open source developer and contributor.