How to combine the Maven Release Plugin with Nexus Staging Plugin?

Viewed 923

I'm releasing an open source project to Maven Central, and I wanted to combine the Maven Release Plugin with the Nexus Staging Plugin, but don't know how.

The Maven Release Plugin performs all I need:

  • the git checks,
  • git repository tag,
  • git next iteration versioning,
  • check out,
  • build,
  • deploy, (<-- This is the one I would like to change)
  • and git branch restore.

All this automation means I can perform a release with a single command line. Awesome.

The only caveat here is that the deploy task above merely delivers the JARs to Maven Central Repository, but does not publish them. I still need to log in to the Maven Central web site, find the release, click on "Close"... wait a few minutes... not ready yet... wait a couple of minutes... check again... oh, it's ready... finally click on "Release". I don't like this manual, error-prone task.

The Nexus Staging Plugin, on the other hand, does the "Close" + "Release" automatically. However, it doesn't do anythine else, like the list of steps described above.

Is there any way I could replace the "deploy" section above with the "Nexus Staging Plugin" instead?

1 Answers

How silly of me. It's incredible how closer you get to an answer when you go through the process of formulating the question.

The solution was very simple. Just by adding the Nexus Staging Plugin to the pom.xml automatically replaces the default "deploy" step.

This is my pom.xml section for the Nexus Staging Plugin:

  <!-- Nexus Staging -->

  <plugin>
    <groupId>org.sonatype.plugins</groupId>
    <artifactId>nexus-staging-maven-plugin</artifactId>
    <version>1.6.7</version>
    <extensions>true</extensions>
    <configuration>
      <serverId>ossrh</serverId>
      <nexusUrl>https://oss.sonatype.org/</nexusUrl>
      <autoReleaseAfterClose>true</autoReleaseAfterClose>
    </configuration>
  </plugin>

Nothing special, as you see. With this, calling the Maven Release Plugin automatically uses the Nexus Staging Plugin, instead of the default deployment.

$ mvn -B release:prepare && mvn release:perform

Fully automated from beginning to end: Git release + Maven Central publishing in one go.

Cheers!

Related