Want to Host on Maven Central?
Want to Host on Maven Central?
Join the DZone community and get the full member experience.Join For Free
Get the Edge with a Professional Java IDE. 30-day free trial.
Recently, when I decided to make my projects available to the Java Community under Open Source license, I did a lit of things like Hosting my code on Google Code, using Maven to build and test the code and also making sure that I have a project site up and running. However, even after all of this, there was one thing that was missing which was the most essential – “Hosting the project files on a repository so that users who may find these utilities useful may use it”.
I started to research on what was possible and after little research I found out that sonatype would allow me to deploy my code to Maven Central Repository. However, after 3 days of trial and error, I have finally been able to release a version of my code to the Central Repo. I am writing this post so that if you ever want to do this, you will not have to go through the same pain as I did.
- A domain name which will be your groupId – I used kapilvirenahuja.com which is used as “com.kapilvirenahuja”
- A PGP key – this is a requirement for you to sign your artifacts and upload it to Central. You can refer to the document here for help on how PGP keys can be generated.
- Have the username and password of your SVN handy, you will need it while performing builds and releases
The easiest way to upload another project is to use the Sonatype OSS Repository, which is an approved repository provided by Sonatype for any OSS Project that want to get their artifacts into Central Repository.
The service is proposed in two variants:
- Maven repository hosting service: You can deploy snapshots, stage releases, and promote your releases so they will be published to Central Repository
- Manual upload of artifacts: The process is mostly automated with turnaround time averaging 1 business day.
Follow the steps in the guide which is self-explanatory. After sign-up, when you are creating the issue for a new project, you will need the domain address. If you do not have a domain registered, you will not be able to proceed.
After your account is created, you will receive email notifications that you are good to go. Follow the steps in the link and update your POM as per Step 6. When you are ready, follow instructions in Step#7 and you should be able to deploy the code to Snapshot directory. If you get 401 error or “Authorization failed”, check for following:
- The groupId in the POM.XML is the same that you registered for
- The Settings.xml has the Nexus username and password. You can run the maven command in -X (debug) mode and see logs to validate the location of the settings.xml file
Release to Central
Once you have the artifacts on Snapshots repository you are past a major step in the process, but the next one is even bigger. The step 7.a.3 seems simple but is not that simple especially if you have only used mvn:compile in most cases. Ensure that you follow standard directory layout anything else and the process will fail at the last step.
The First step is to Clean up Release using Maven plugin
You will notice that it will be done quickly (apart from the time it takes for maven to download dependencies and plugins).
Run the following command. You will have to pass the username and password through mvn. The command should be
mvn release:prepare -Dusername=username -Dpassword=password
It will do the following:
- Ask for the version number for the current release
- Ask for the version of the tag that will be created, should be same as the release number provided above
- Ask for the next version of the release – you can choose to provide a major or minor release.
Please be careful when selecting the version numbers, because this process will update the POM files and also the subversion repository by adding new tag and also updating the POM file in the current working location.
mvn release:perform -Dusername=username -Dpassword=password
This is a non-intrusive method and will simply upload everything to the repository. If you miss the username and password, the build will fail without any descriptive errors and you will keep wondering what went wrong.
Opinions expressed by DZone contributors are their own.