Skip to main content
  1. Posts/

Publishing to Maven Central

·392 words·2 mins

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

Demise of JCenter>

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?>

Why not Jitpack? #

I agree with the points Saket Narayan made here:

Publishing to Maven Central>

Publishing to Maven Central #

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

https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/

Publish plugin>

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>

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:

https://github.com/saket/startship

Examples>

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:

https://github.com/chrisbanes/accompanist

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