Push your JAR to MavenCentral

⚡️Hudson Ⓜ️endes
4 min readApr 15, 2020

See the breadcrumbs (and scripts) I left on the way to publish your opensource JAR to MavenCentral via Sonatype Central.

Background

I currently work as a Lead Software Engineer at AIQUDO, Voice to Action (former Boxfish & Sofia Discovery) in the UK division. And for over a year I have contributed to one of the company's open-source project: https://github.com/bxfsh/boxfish-commons-web-model

Publishing versions of this open-source to Sonatype central has proven to be a tricky process sometimes. I don't know if I am the only one experiencing these problems, but the maven clean-prepare-release sequence seems to be somehow broken.

Everytime I tried to push, I had to execute a certain number of steps which have always been hard to remember (releases of this open source sometimes are 3 months away from each other).

So I decided to write this article to serve as bread crumbs and provide scripts that I could re-use in order to deploy JARs to Sonatype Central and, then, to Maven Central.

The Manual Steps

At this point, you will be in a snapshot version. From the "-SNAPSHOT" version, start preparing your build

mvn release:clean release:prepare

Check your github repository and notice that a new tag release was created. This tag has a problem: it has your "-SNAPSHOT" version defined in your pom.xml., and it will break the mvn release:perform later on, so we have to fix it.

The procedure here is not so complicated: we must delete the existing tag, create a new one with the release version number

git tag --delete boxfish-commons-web-model-1.0.4
git push origin :boxfish-commons-web-model-1.0.4
mvn versions:set -DnewVersion=1.0.4
git add -A
git commit -m "Version rollout"
git push
git tag boxfish-commons-web-model-1.0.4

Create a git tag and push it:

git add -A
git commit -m “Version rollout”
git tag boxfish-commons-web-model-1.0.4
git push origin :boxfish-commons-web-model-1.0.4

Return the state that the mvn release:prepare has left you in before continue.

mvn versions:set -DnewVersion=1.0.5-SNAPSHOT

Everything ready, time to perform the release

# it will prompt your for your GPG password 4 times!
GPG_TTY=`tty` mvn release:perform

The key in the command above is this GPG_TTY=`tty` (in my case, because I was in the OSX). It will FAIL you if you try to run without it, because it will not prompt you for the passsword.

Moving on, it's time to login to your Sonatype Central UI, and do the very final steps.

  1. Click on the left handside "Staging Repositories"
  2. Type in your organization name on the top right handside
  3. Select the repository
  4. Check the content: it must have all signed JARS and Sources
  5. Click "close", type in a comment and confirm
  6. For more intel, check the activities

At this point your opensource should already be available at the sonatype central "Staging" repository.

However, it will take a few hours (or days) to get published to the Production repository and then replicated to Maven Central.

Can't be rushed: this is something that is out of your control.

After the sync process is completed, you will be able to see your JAR available in both https://oss.sonatype.org/content/repositories/releases/ and in http://mvnrepository.com like the ones below.

Wanna keep in Touch? LinkedIn!

My name is Hudson Mendes (@hudsonmendes), I’m a 38 years old coder, husband, father of 3, ex Startup Founder, ex-Peloton L7 Staff Tech Lead/Manager, nearly BSc in Computer Science by the University of London & Senior AI/ML Engineering Manager.

I’ve been on the Software Engineering road for 22+ years, and occasionally write about topics of interest to other Senior Engineering Managers and Staff Machine Learning Engineering with a bit of focus (but not exclusively) on Natural Language Processing.

Join me there, and I will keep you in the loop with my new learnings in AI/ML/LLMs and beyond!

--

--

⚡️Hudson Ⓜ️endes

⚡️Staff AI/ML Engineer & Senior Engineering Manager, #NLP, opinions are my own. https://linkedin.com/in/hudsonmendes