Deploy to Maven Central Repository

Do you need to make your Java library publicly accessible? Is your project hosted on GitHub? Do you like idea of “all-in-one deploy to Maven Central Repository” button? I am going to show how to set it up with usage of maven-release-plugin. Source code is hosted on GitHub, so SSH access to source control will be also described.

There are various steps needed to set up environment for your project. I followed a lot of steps from official SonaType guide, therefore I will refer to it when needed. But this guide also describes a lot of techniques that are not needed for configuring “deploy to Maven Central repository” button.


My first approach was to create Jenkins job that would represent the “Deploy to Maven Central” button. This idea is much cleaner for me  than pushing from my development machine. I was trying it hardly but couldn’t make Jenkins SSH Agent plugin to register my SSH identity when maven-release-plugin is pushing version update to GitHub. Therefore very simple Linux Bash script is involved in two steps.

1. Create SonaType JIRA ticket for registration of your groupId

SonaType drives one of the biggest Nexus repositories. It is needed to deploy Java artifact there before it can be synced into Maven Central repository. In order to release Java library into SonaType Nexus repository, JIRA ticket is needed. SonaType guide includes detailed description how to create it.

Pick up Maven groupId reflecting your top level domain. It is typically same as main Java package (e.g., not This is because you don’t want to create JIRA ticket for each project/library under your domain/main package/groupId.  Here is more reading about Java package naming convention.

2. Inherit your Maven artifact from SonaType OSS pom.xml

SonaType parent POM contains

  • URL to SonaType Nexus repository
  • Configuration of Maven plugins
    • Enforcer plugin
    • Release plugin – this one is most important
    • Source plugin – generates JAR with sources
    • JavaDoc plugin – generates JAR with JavaDoc comments
    • GPG plugin – signs artefact with GnuPG tool (this is required by Maven Central Repository)

Existence of this parent POM is handy because otherwise you would need to specify all plugins in your POM. The only problem is that plugin versions are slightly out of date, so I decided to override some versions in my POM this way:


Crucial version update here is GPG plugin one, because updated version have handy features described section about GPG signing.

3. Configure GPG signing of Maven artefact

This is needed because of security policy of Maven Central repository. Include various sub-steps:


F21879F3 is my public GPG key ID. gpg –list-keys command would list it for you. Passphase is password for your private GPG key. .gnupg folder is typically generated in your home directory.

4. Set up your credentials for SonaType Nexus repository

Needed for push to SonaType Nexus repository. Same as SonaType JIRA credentials. Again in settings.xml:


5. Fill pom.xml mandatory sections

6. Set up SSH access to GitHub

Follow these sub-steps:

7. Create “Deploy to Maven Central” button

Maven-release-plugin needs to push/check-in version update to source control system and tag the revision. In my case the code is hosted on GitHub. Therefore I need to register my SSH identity (generated in previous step) before invoking maven-release-plugin’s goals. This is done by bash script located alongside pom.xml:

# Deploy maven artefact in current directory into Maven central repository 
# using maven-release-plugin goals

read -p "Really deploy to maven cetral repository  (yes/no)? "

if ( [ "$REPLY" == "yes" ] ) then
  ssh-add ~/.ssh/lubos.krnac
  ssh-add -l
  mvn release:clean release:prepare release:perform -B -e | tee maven-central-deploy.log
  ssh-add -D
  echo 'Exit without deploy'

Make the script executable by

chmod +x

 8. Push the “Deploy to Maven Central” button

Just run


confirm and enter SSH private key passphase if required.

9. Release artifact via SonaType Nexus repository

When the artifact is pushed to SonaType Nexus repository. You need to release it. Finally you would need to add comment to the SonaType JIRA issue you created at the beginning and wait until somebody reviews your artifact and sets up the sync to Maven Central. Of course JIRA part would need to be done only once.


Example project configured this way is hosted on GitHub. (It’s tiny testing library).

6 thoughts on “Deploy to Maven Central Repository

  1. Thanks for putting up this post. It’s a nice and concise guide for something I had to cobble together last summer, which was really painful.

    Recently I’ve been meaning to give Bintray a try too. Have you tried it?

    I think this is the guide I saw.

    Anyway, thanks again

  2. Hello Lubos, I am Derek Weeks from Sonatype. We are really happy to see your blog discussing Nexus and we would love to bring it some more visibility. We recently started up a new Nexus community site with loads of articles, free training, videos, and members only features. If you are interested, we would love to cross-post your blog on the community, giving your article and you as the author more visibility to the rest of the Nexus community. I am sure others would find the article just as useful as I did. Our Nexus community site “TheNexus” can be found at:

    Reach out to me at “weeks[at]sonatype dotcom” and I can introduce you to our Nexus community advocate, Mark Miller. We can then work to get your article up on the site. Of course, Sonatype will help with more visibility by promoting the article through our community, twitter, LinkedIn, G+, Facebook and other communities.

    Are you in? Let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>