How to publish a Java Maven project to the Maven central repository

Laptop

Prepare to publish packages

Publishing a Java artifact is not as trivial as deploying Python or JavaScript packages.

Basic requirements

You need to have a domain name on which the package will be hosted or posted. You don’t have to have a domain name for each package, you can use a GitHub.io page generated from your project, but for real packages you need a professional domain. In this case, the domain is jdesk.mathsoftware.engineer .

It’s semantic, so you stick to the subsets: engineers (all engineers) -> math software (me, a certain engineer) -> jdesk (my project).

Later, for the standard Java packaging convention, you will need to use reverse DNS. That is, engineer.mathsoftware.jdesk .

Security

You will also need a private key to sign the artifact. Generate a GPG key to use. Then run gpg –gen-key and configure it as you would when creating a GitHub GPG key.

Build tool

You can use Gradle or Maven as your build tool. Due to the nature of this project, I decided to use Maven in the beginning. So, this article will use Maven to customize the pom.xml file.

You need to install Maven on your system. Go to the Apache Maven download, unzip the file, and then add an entry to the Path environment variable with the value of the bin directory, for example “C:\Users\user\apache-maven-3.8.5\bin” (Windows). Verify this installation by running “mvn –version” in a new terminal.

Create a JIRA account and submit a ticket
First, you’ll need a Sonatype JIRA account to open a new ticket and request access to publish your artifact.

This sounds very strange, at least the first time I had to do it. Just go ahead and do it.

Then create a JIRA ticket to fill in your information. I’ll include screenshots so you can see how to proceed. Then a bot will help you fulfill your request.

That was the general process. You can read Publishing artifacts to Maven Central | JetBrains Space and OSSRH Guide – The Central Repository Documentation for more details.

You will need to upload your PG key, read Working with PGP Signatures – The Central Repository Documentation to complete this step. Remember to set a secure passphrase, an expiration date, and to store your key and its backup securely.