Publishing to Maven Central

February 11, 2021

A quick guide to show you how easy it can be to publish libraries to Maven Central.

Demise of JCenter

In case you missed it, the JCenter is shutting down in May 2021:

No more submissions will be accepted at the end of March 2021, and the packages will be served until the end of January 2022.

With the demise of JCenter, the need to publish somewhere else is something which is top of mind for many library developers; especially for those Android library developers, including me.

For me, Maven Central is now the obvious place to publish your libraries.

Publishing to Maven Central

The post written by Waseef Akhtar goes into detail on how to setup your Sonatype account, and publish your first library:

To summarize:

  • Create a ticket in Sonatype Jira

  • Setup DNS referencing on your domain for verification purposes.

  • Setup your library project with Gradle plugin for publishing

  • Create a GPG key for signing your release artifact

  • Configure signing parameters with the created GPG key

  • Upload your artifact to Sonatype

  • Publish your library via Sonatype

Publish plugin

As mentioned above, we are using the gradle-maven-publish-plugin plugin for publishing:

It handles all the docs source sets for you, as well as support for Dokka if you're using Kotlin. Highly recommended!

Automated publishing

The gradle-maven-publish-plugin I mentioned earlier has support for this. Once setup you can call ./gradlew closeAndReleaseRepository.

Alternatively, Saket has created a standalone command-line tool which enables similar, called Startship:

However, using Maven Central and Sonatype requires you to manually close and release your library version. Personally, I like this step, as it keeps me in control of exactly what is released. This is especially important on Maven Central, as anything which is published is immutable. You can't change it.

Once you finished release your library, you should go back to your ticket in Sonatype Jira and leave a comment so that their team can close your ticket.

Examples

Below are some to look at for how to setup your library to publish to Maven Central.

And that's about it!