DatumEdge

The website of James Shaw, a PhD student researching numerical methods for the atmosphere at University of Reading

Publishing from GitHub to Maven Central

7 May 2012

Unless your project is hosted by an approved foundation such as Apache or Codehaus, you won't be able publish artifacts to Maven Central directly. Instead, Sonatype provide their own Nexus repositories for open source projects, and synchronise these with Maven Central.

In this post I've tried to condense Sonatype's instructions, and include snippets from the POM file of my project, redis-launcher.

Getting set up

  1. Add source code management information to your POM:
  2. Create a GPG key pair and publish the public key. See the Sonatype documentation for instructions.
  3. Check that your project POM meets the requirements for syncing
  4. Create a Sonatype JIRA account and raise a ticket to get your Nexus repository set up

Using Maven to release to Sonatype Nexus repository

  1. Add the maven-release-plugin to your POM:
  2. Add the Sonatype repositories:
  3. Configure artifact signing:
  4. Edit or create ~/.m2/settings.xml to include your credentials: Maven does have a method to avoid storing plaintext passwords, but I have yet to try it.

Cutting a release

To cut a release, issue mvn clean release:prepare. Say your project is at version 0.1-SNAPSHOT. Preparing a release will remove the -SNAPSHOT suffix, commit and tag the code on github, then update the project version to 0.2-SNAPSHOT.

If you need to undo the release, revert the changes with git reset --hard HEAD~2, and delete the tag with git tag -d redis-launcher-0.1 followed by git push origin :refs/tags/redis-launcher-0.1.

Publishing to Sonatype

  1. If all is well, you can publish the project artifacts to Sonatype by issuing mvn release:perform
  2. Log into Sonatype Nexus and find your artifacts under Staging Repositories
  3. Close, then release the artifacts. Sonatype have some good instructions on using their web interface. You can automate these steps using the Maven repository management plugin, though I haven't tried it myself.
  4. Add a comment to your JIRA ticket to say that you've promoted the release
The next time Sonatype synchronises (usually every few hours) your artifacts should be made available on Maven Central.