Skip to main content
Publishing to Maven Central

Publishing to Maven Central

·456 words·3 mins

This is just a quick post to highlight how easy it can be to publish libraries to Maven Central.

Demise of JCenter
#

In case you missed it, JCenter is shutting down in May 2021: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

With the demise of JCenter, the need to publish somewhere else is probably something which is top of mind for many library developers. This post won’t go into the nuts and bolts of how, but instead point to existing resources which will help.

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

Why not Jitpack?
#

I agree with the points Saket Narayan made here:

Publishing to Maven Central
#

Márton Braun’s post goes into detail of how to setup your Sonatype account, and publish your first library:

Publishing Android libraries to MavenCentral in 2021
MavenCentral is the place to be for Android libraries, but publishing there is no easy task. Here's the step-by-step guide on how to do it.
getstream.io

Publish plugin
#

Marton uses an updated version of my gradle-mvn-push script (I think), but I’ve personally moved to using the gradle-maven-publish-plugin plugin by Niklas Baudy instead: https://github.com/vanniktech/gradle-maven-publish-plugin

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

Automated closing + releasing
#

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.

But, I do understand that some people want to automate this as much as possible, so there are a few ways to automate the release:

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:

GitHub - saket/startship: Never open sonatype's website again for releasing your libraries on maven central.
Never open sonatype's website again for releasing your libraries on maven central. - saket/startship
github.com

Examples
#

If you’d like to look at some examples for how to setup your library to publish to Maven Central, here’s a few below:

GitHub - google/accompanist: A collection of extension libraries for Jetpack Compose
A collection of extension libraries for Jetpack Compose - google/accompanist
github.com

If you know of any other open source examples, let me know.