Simplified Releases to the Central Repository with Nexus


September 30, 2013 By Manfred Moser

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:

mvn versions:display-plugin-updates

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

mvn clean install

I started the release process using the Maven Release Plugin:

mvn release:prepare

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:

mvn release:perform

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.

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

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:

cd target/checkout
mvn nexus-staging:release

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 ;-)