Table of Contents
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:
3. JitPack builds artifacts only when they're requested for the first time. Depending on the time it takes to build, gradle may time out trying to resolve the artifact. This sort of flakiness is hard to tolerate for some companies.— Saket Narayan (@saketme) February 3, 2021
Publishing to Maven Central #
Márton Braun’s post goes into detail of how to setup your Sonatype account, and publish your first library:
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:
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:
If you know of any other open source examples, let me know.