How to Publish a Java Library to Maven Central

01 Aug 2021  Sergio Martin Rubio  6 mins read.

The process of publishing a Java library to Maven Central is not as straightforward as you might think and we will go through all the required steps to share your new shiny Java library with the of world.


Nexus Account Setup

Maven central requires having a unique Group ID that is usually a domain name reversed. If you own a domain, you can use it e.g. com.sergiomartinrubio, otherwise you can simply use your GitHub account e.g. com.github.sergiomartinrubio.

  1. Create a Sonatype Jira account. Use your email address from your domain if possible.
  2. Create Create a new Jira Issue as follows:
    • Summary: can be something like Create new com.sergiomartinrubio project.
    • Group Id: will be something like com.sergiomartinrubio or com.github.sergiomartinrubio.
    • Project URL: can be your website or where you document the library (e.g. GitHub account).
    • SCM url: is the host where the library is uploaded. e.g.
    • Username: is the chosen username. e.g. sergiomartinrubio
    • Description: can be something like I intend to publish open source projects.
  3. Wait for a Reply for the domain verification. If you own a domain you can verify the domain by adding a TXT record to the resource records. The resource record must include the Jira ticket ID. e.g. OSSRH-71520. In case you don’t own the domain you’ll have to setup some coordinates. The response is usually quick.

If everything went well a comment with a guide for publishing your library is added.

Once you account is verified you should be able to access the Nexus Repository Manager where you will be able to see the artifacts of your uploaded libraries.

Create GPG Key

GPG is required by Maven Central in order to be able to publish a libraries.

  1. Install GPG. For MacOS users you can run: brew install gpg.

  2. Create key: gpg --full-generate-key. It is recommended to use your real contact information and a secured password.

  3. Upload public key to a server so sonatype can find it:

    gpg --list-keys # list created gpg keys
    gpg --keyserver --recv-keys <key_id> # upload key to server

You can also export the gpg key with gpg --export-secret-keys <key_id> > sonatype_upload.gpg

You can find more detailed information on the Sonatype GPG configuration page.

Configure Maven Settings

nano ~/.m2/settings.xml

Configure your Maven Project File

Go to your pom.xml.

Add project metadata:

  • Group Id, artifact Id, version, project name, description, url…

    <description>Client library for interacting with Telegram Bots</description>
  • Organization information. i.e.:

  • Licenses. i.e.:

         <name>Apache License, Version 2.0</name>
  • Software Configuration Management (scm) information. i.e.:

  • Developers information. i.e.:

        <name>Sergio Martin Rubio</name>

Configure Maven Distribution Management:

You might need to include the following distribution management entry if you are going to publish artifacts to the snapshots repository.


Include the following Maven plugins:

  • nexus-staging-maven-plugin: is used to perform the deployment to the Nexus repository.

  • maven-source-plugin: plugin for generating the a jar file with the source files of the project. This is required by Maven Central.

  • maven-javadoc-plugin: used for generating the javadoc files for the project. This is required by Maven Central.

  • maven-gpg-plugin. This is used to sign the project artifact with GPG.


Sonatype documentation also provides a detailed guide to configure the different Maven plugins.

Publish you Java Library

Before publishing your library you might want to update the version. You can simply run the following Maven command:

mvn versions:set -DnewVersion=1.0.0

You can also create a Maven profile for publishing the artifact so the release is not executed by mistake. Include plugins from the previous section here:

      nexus deploy, javadoc, source and gpg plugin

Now you can run the following Maven command:

 mvn clean deploy -Prelease

If everything went well you should be able to see your library at Nexus Repository Manager, however, It might take a while to show up. Also, the library will also appear at, but I noticed this takes about half a day or even a day.


You are using MacOS you might need to add to your .bash_profile or .zshrc:

export GPG_TTY=$(tty)

Source Code

Photo by Devon Divine on Unsplash