We finally jumped through all the hoops to publish on Maven Central. What is Maven Central? Only the primary repository for maven-based Java projects!
There are tutorials on the Sonatype site itself, but the basic steps are here.
So you think you want to take to the next level with Java? We published some JARs on Sourceforge (remember that one?) but this is intense.
Prove Ownership
This one was interesting, because you must “claim” your namespace via a Jira ticket in the Sonatype Jira system. Make sure to sign up first.
You literally make a ticket to the effect of “hey there, I want to claim ‘com.escape-technology-llc’ as a namespace”. However, you must also submit “proof” that you own the domain you are claiming. After all, any old person could come along and try to claim our super-cool domain name…
There are several ways to do it; we ended up adding a TXT record to our DNS, with the Jira ticket ID as the value. We had a slight complication due to “split” hosting; our web and DNS are different providers. Since you are in a Jira ticket, it was simple enough to provide the extra info to do the lookup.
Plugin Pileup
Now that you are “in the club” comes the task of preparing your sweet piles of Java for the submission process.
Since it’s “maven all the way down” it will come as no surprise that the way to get JARs into Central is via maven plugins. Also required are a handful of “documentation” elements you may not have all of them (yet). Adding Sonatype servers to the distributionManagement
element is also required.
Central has “required” plugins along with the publishing-related plugin from Sonatype:
- maven-xxx-plugin (clean, resources, compiler, surefire, jar, install, deploy, site)
- nexus-staging-maven-plugin (sonatype)
- maven-source-plugin
- maven-javadoc-plugin
- maven-gpg-plugin
Some have specific configurations; again the Sonatype “manual” is quite good just copy and paste. Note that you must provide both javadoc and source JARs along with your built JAR.
The final touch is adding your Sonatype credentials into settings.xml
and you are almost there!
I Forgot My Key
Did I see a “9er” in there? Yes there is a GPG plugin, because you must sign everything for submission. We installed Kleopatra and set up a key pair that way.
Complete the settings.xml
by adding the key passphrase and GPG executable location and now you are there!
Jibe Ho!
At this point, you can simply mvn clean deploy
and watch the magic! Depending on your environment, maven may prompt interactively for the passphrase.
This should be the end of the tale, but for the epilog. Log in to the Nexus Repository Manager and ensure your artifact(s) are replicating, because you publish to a staging repository from maven. When we did so, we found our artifacts already in the public repository!