In my previous article I published information about publishing JAR/AAR library to the Maven Central Repository. A few steps of that process were automated, but a few of them were still manual. I mean closing and release process which had to be done by manual clicking on the Sonatype website. Fortunately, it’s possible to automate it. In order to do that, I used gradle-nexus-staging-plugin developed by Codearte. Thanks to this plugin I could get rid of the remaining manual steps left in the release process.

Please note, if you want to apply configuration described in this article to your project, you need to perform the steps described in the article about Publishing JAR/AAR to the Maven Central.

In my project, in the top-level build.gradle file I had to do the following setup:

In order to get YOUR_STAGING_PROFILE, we need to call the following command available in the plugin:

When we are done, we can simply call:

These two gradle tasks will upload our artifact, close and release it, so we won’t have to perform any manual steps in that process. After that, we just need to wait for the Maven sync as usual.

My complete release.sh script looks like that:

Before upload and release, I also clean everything, build an artifact, run tests and static code analysis. It’s not required, but it’s good to do that.

If you are interested in complete project configuration, you can have a look at the https://github.com/pwittchen/ReactiveNetwork repository. It’s an Android library, but the same configuration can be applied to any JVM project built with Gradle. I have performed library release with this plugin a few times and it seems to work well.