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.
- Create your JIRA account
- Create a New Project ticket JIRA ticket example:
- Install GnuPG
- Generate gpg key by entering required parameters:
- Send generated key to key server:
gpg --keyserver hkp://keys.gnupg.net --send-keys YOUR_KEY
- Generate Access User Token from oss.sonatype.org
- Go to your profile
- Go into User Token tab
- 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"
<username>*Username Obtained from Sonatype*</username>
<password>*Password Obtained from Sonatype*</password>
- 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.
- 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
- Now, go to oss.sonatype.org and login
- Go into Staging Repositories
- Find your project at the bottom, choose it and click close button at the top
- 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
- 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.
- 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
- 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
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.
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!