Beginner guide to Maven Central publishing

Beginner guide to Maven Central publishing

May 4, 2020
Maven Central is the central repository for Maven, the main Java repository where you can find libraries and components. Java developers are using this repository to create java application and manage efficiently dependencies.
I use to be very intimidated by pushing an artifact (i.e. a java package) to Maven Central, as it seems very complicated to me by the past. For example push to npmjs seems more easy (npm publish !).
This article is just a guide (at least for myself) on how to push easily some content to Maven Central, with just a Github account.

Before starting why pushing to Central ?

Maybe you are asking yourself why pushing to Maven Central when we have in 2020 multiple way of releasing java package ?
  • Maven Central is the main repository. You don't have to declare an additional¬†repository¬†in your¬†pom.xml, it is just available by default in your Maven/Gradle... project.
  • Other main repositories are generally synced to this main one. Here I will show you how to publish to¬†OSSRH¬†(OSS Repository Hosting) that is the main way to publish package. This repository is synced to Maven Central.
  • There is not so much other solution available as pure repositories, for free (I want to publish open source content, I don't want to pay for that)
  • GitHub Package¬†seems very promising¬†but¬†end-users must manipulate the¬†repositories¬†part of the¬†pom.xml¬†file and must be¬†authenticated¬†even for public packages.

First step, create account and get a groupId

  • create a JIRA account¬†here
  • Create a new issue using¬†this¬†template.
notion image
The issue must describe the project you want to share. The most important information in the case is the groupId. The groupId is the main identification of you as a package provider, so it must be unique. It is generally an url in reverse order like :
For a hobbyist developer using github or equivalent git platform I recommand the following : io.github.YOURUSERNAME.
Once the ticket is created, you will have to prove that you own the groupId provided (for GitHub it's just a matter of create a new temporary project repo)

Second step, make your project pretty

Here is the small maven project I want to share on Central:
It's a very simple library that is designed to read a specific file format.
There is a long list of requirement for your project to be accepted on OSSRH, you can read it here.
To resume the requirements:
  • you must supply javadoc (using¬†maven-javadoc-plugin¬†for example)
  • you must supply sources (using¬†maven-source-plugin¬†for example)
  • you must sign the files with GPG (using¬†maven-gpg-plugin¬†for example)
  • the¬†pom.xml¬†file must contains enough metadata:
    • groupId¬†(unique namespace like¬†io.github.USERNAME)
    • artifactId
    • version
    • name
    • description
    • url
    • licenses¬†part
    • developers¬†part
    • scm¬†section
For reference here his my pom.xml file that fit the requirements.

Finally deploy !

Do not forget to install gpg and create a new key if you don't have one (I found again my key generated in 2004 yes I am old !)
brew install gpg # mac example
gpg --gen-key
Using Maven it is needed to use the right distributionManagement and help yourself by using the nexus-staging-maven-plugin plugin:
(again this is available in my pom.xml)
You must auth on the OSSRH repository by modifying your settings.xml file under ~/.m2:
Use the id and password you have created at the start of this article.
And then if your maven project have already the right version you can directly push to OSSRH using:
mvn clean deploy
The property autoReleaseAfterClose of nexus-staging-maven-plugin set to true will directly push the artifact from snapshot to the release repository.
Note: to change your Maven project version you can use the following:
mvn versions:set -DnewVersion=1.2.3 # set the version
mvn versions:commit # remove the pomBackup file
mvn versions:revert # back to previous version
After a few hours you will be able to see your package on Maven Search
notion image
Nice job !

Other stuff to speak of

During my exploration I have found this tool :
notion image
It seems to be an easy way to consume an existing git repository as maven dependency. I have not yet tested it but it feels like the flexible I miss with Maven (Composer for PHP allow to consume git repo, npmjs allow to consume git repo, etc...)


  • This article rely a lot on the OSSRH guide¬†here.


Well there is more steps than npmjs but it is very affordable and you can do the same. Maybe it can be also the time for me to explore Gradle or other new tooling around Java... Let me know if you have already pushed an artifact to Maven Central ? Thanks for reading !