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
- Add source code management information to your POM:
- Create a GPG key pair and publish the public key. See the Sonatype documentation for instructions.
- Check that your project POM meets the requirements for syncing
- Create a Sonatype JIRA account and raise a ticket to get your Nexus repository set up
Using Maven to release to Sonatype Nexus repository
- Add the maven-release-plugin to your POM:
- Add the Sonatype repositories:
- Configure artifact signing:
- Edit or create
~/.m2/settings.xmlto 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
- If all is well, you can publish the project artifacts to Sonatype by issuing
- Log into Sonatype Nexus and find your artifacts under Staging Repositories
- 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.
- Add a comment to your JIRA ticket to say that you've promoted the release