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
npmjsseems more easy (
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.
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
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
repositoriespart of the
pom.xmlfile and must be authenticated even for public packages.
- create a JIRA account here
- Create a new issue using this template.
The issue must describe the project you want to share. The most important information in the case is the
groupIdis 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 :
Once the ticket is created, you will have to prove that you own the
groupIdprovided (for GitHub it's just a matter of create a new temporary project repo)
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
- you must supply sources (using
- you must sign the files with GPG (using
pom.xmlfile must contains enough metadata:
groupId(unique namespace like
For reference here his my pom.xml file that fit the requirements.
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
distributionManagementand help yourself by using the
<distributionManagement> <snapshotRepository> <id>ossrh</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> <build> <plugins> <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> <version>1.6.7</version> <extensions>true</extensions> <configuration> <serverId>ossrh</serverId> <nexusUrl>https://oss.sonatype.org/</nexusUrl> <autoReleaseAfterClose>true</autoReleaseAfterClose> </configuration> </plugin> ... </plugins> </build>
(again this is available in my pom.xml)
You must auth on the OSSRH repository by modifying your
<settings> <servers> <server> <id>ossrh</id> <username>your-jira-id</username> <password>your-jira-pwd</password> </server> </servers> </settings>
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
nexus-staging-maven-pluginset 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
Nice job !
During my exploration I have found this tool : https://jitpack.io/
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
npmjsbut 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 !