Enterprise Java

How to publish jar to Maven central

You created your brand new project and you want to release it to maven central so people can use in their maven based project. It is not a really straightforward thing to accomplish so I wanted to write a step by step guide on it (based on his stackoverflow post). 

Create your jira account on sonatype

-Login to your jira account

Create a ticket for your project: For this step you will need a group id, a project website and a link to your source control. 

I used “com.sezinkarli” for group id because I own this domain. If you don’t have a domain and you use github, you can easily use “io.github.yourusername”

Project website can be your github link for the project and you can link your github .git link as source control. So as you can see, github will be really useful here.

-Create a PGP key. You can download it here. Then open a command prompt and do

gpg –gen-key

It will generate our public and secret keys and sign them.

In the meantime it will print something like this:

gpg: key [Your key] marked as ultimately trusted

We will use this key for the following command:

gpg –keyserver hkp://pool.sks-keyservers.net –send-keys [Your key] 

-Now we will update our user’s maven settings. Go to your .m2 folder and edit/add settings.xml .

      <username>your jira username for sonatype</username>
      <password>your jira passwordfor sonatype</password>
        <gpg.passphrase>passphrase you used for gpg key</gpg.passphrase>

-Now we will update our project’s pom.xml .

Add parent:


Add distribution management:


Add build plugins:


-Now we have everything in place. After we made sure from sonatype jira ticket that we are good to go (they do a check for group id), we can deploy our project to maven central:

mvn clean deploy

And that’s it!

I had a problem while deploying because I did not have any javadoc. After I added it, everything worked like a charm.

Published on Java Code Geeks with permission by Sezin Karli, partner at our JCG program. See the original article here: How to publish jar to Maven central

Opinions expressed by Java Code Geeks contributors are their own.

Sezin Karli

Mathematics Engineer & Computer Scientist with a passion for software development. Avid learner for new technologies. Currently working as Senior Software Engineer at Sahibinden.com.
Notify of

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

Inline Feedbacks
View all comments
Back to top button