Publishing To Maven Central Repository

Recently I went through the process of deploying my opensource project EasyDiameter to Maven Central repository. At first, the process seemed confusing and there were lots of steps to go through. I decided to create this tutorial for myself to use later if I ever go through the same process.

SonaType provides repository hosting service for open source project binaries. We will deploy our project to SonaType Nexus repository and then they will sync it to Maven Central.

Sonatype uses JIRA to manage requests. First, we need to create JIRA ticket. As soon as the ticket is resolved, we can deploy our project.

  1. Create your JIRA account
  2. Create a New Project ticket
  3. JIRA ticket example:

    The process may take up to 2 business days. When the ticket is resolved we can continue to the process.
    Before deploying our project we need to sign it with GnuPG.

  4. Install GnuPG
  5. Generate gpg key by entering required parameters:
  6. Send generated key to key server:
    gpg --keyserver hkp://keys.gnupg.net --send-keys YOUR_KEY

  7. Generate Access User Token from oss.sonatype.org
    1. Go to your profile
    2. Go into User Token tab
    3. Create your access token


    After creating the Access Token, we will use it in Maven’s setting.xml. Where you can find the Maven’s setting.xml is beyond the scope of this tutorial.

    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

             
      <servers>

        <server>
          <id>ossrh</id>
          <username>*Username Obtained from Sonatype*</username>
          <password>*Password Obtained from Sonatype*</password>
        </server>
     
      </servers>

    </settings>
  8. We are ready to deploy our project, but if we deploy the project in this state, it will fail at POM validation step because we haven’t provided necessary information in our pom.xml. We need to provide some information such as licence, scm, distributionManagement, build(compiler, source, javadoc, gpg) etc. You can check my EasyDiameter project’s pom.xml to see an example POM file.
  9. Let’s deploy our project using the passpharase we defined while creating gpg key
    mvn clean deploy -Dgpg.passphrase=******

    We could also provide this passphare in Maven’s setting.xml

  10. Now, go to oss.sonatype.org and login
    1. Go into Staging Repositories
    2. Find your project at the bottom, choose it and click close button at the top
    3. You will see the results of validation in the activity tab. You may need to click refresh button at the top couple times before validation step is fully completed
    4. If validation fails at some step, check and fix the related error. Drop the project from staging repository and deploy the new project. Go through same steps again.
    5. If everything went okey, you will see Release button is activated on top. After clicking the Release button, your project will be synced to Central Repository
    6. If it is the first time deploying your project, you need to reply your resolved JIRA ticket that you deployed your project. Only after that they will sync it to Maven Central and you will be able to see your project on search.maven.org within couple hours

Voila! We have successfully deployed our project to Maven Central. SonaType has amazing documentation and video tutorials on this topic. Here you can see the video tutorials that will help you quickly deploy your project.
Thank you for reading so far! And thanks for contributing to the community with your open source projects!

If you liked the content please share it!

You may also like...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.