Publishing of your artifact to maven central
Recently, I finished my pet-project and wanted to publish it to maven central. As I found out later, publishing is not a trivial thing. In this post, I’m going to show you all steps which you need to go through to publish your artifact.
My project is a scala wrapper for a very useful library testcontainers-java. As you may assume, it’s written in scala, but all the following is applicable for java/groovy/whatever language project if it’s built by gradle.
Preparation
First of all, you need to request a group id reservation. To do so, you need to sign up in Sonatype’s JIRA and create an issue where you’ll have to ask to approve your group id. This is how I did that.
GPG Keys
The next step is a creation of a gpg key. You need to install some additional utilities, on macos it looks like that
brew install gpg gpg2
.
Now, tet’s create a key.
Pick default answers to the first two questions. Then enter two years as an expiration period. And fill out personal information.
Now you can list all your keys:
Copy a keyid of your key and distribute it as follows:
A bit more details on this step are here.
Gradle script
Now we can touch the project. Here are changes which should be made to your build.gradle
:
This code allows publishing of releases and snapshots to oss.sonatype.org. You just need to adjust pom.project
section to match your project information.
And to make it all work, we need to modify ~/.gradle/gradle.properties
by adding a several properties:
More information on it is here.
Publishing
It seems it’s time to deploy your artifact. Make sure your work with non-snapshot version and then execute:
Once it’s done, you need to promote your release. To do so, you have to go to this page. In the table with repositories, you’ll see one that looks like your group id but without dots. Go in there and then click ‘Close’ in the top menu. Refresh the view in a few seconds and go to the ‘Activity’ tab - if you did everything correctly on the previous steps, you’ll see no errors and a button ‘Release’ will be enabled (it’s located to the right of ‘Close’ button), click on it and that’s pretty much it.
Enjoy having your own artifact in maven cental!