Publishing to Maven CentralThu, Feb 04, 09:26 AM
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:
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:
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.