Jinyan Cao

Apache Maven.jpgIf you have used any Android open source libraries (and you absolutely should since we should never reinvent the wheel), I’m sure that you’ve seen this before on Github.

1-Ckvz88EKKObcXPK17pYOGA.pngShameless self promo for my Ticker library

There are many documentations across the web regarding this topic, but most of them are geared toward general Java libraries and hard to decipher through since not all of the steps are necessary for an Android project. In this post I will try to simplify the process and outline the things specific to publishing an Android project so you can focus on the more important stuff.

Claim your namespace

The very first thing that you need to do is to claim your namespace on Maven. First, sign up for a Sonatypes account here. Upon signing up, create a new JIRA ticket claiming your namespace.

  • Summary: this can just be a quick summary saying that you want access to a particular namespace.
  • Description: similar to summary, can provide more information regarding where you are hosting the projects or other credentials proving that you are the owner for the namespace.
  • Group ID: since we are focusing on Github repos, the group ID should be com.github.{your_github_username}, e.g. com.github.jinatonic.
  • Project URL: this is your Github project URL, e.g. https://github.com/robinhood/ticker. If you don’t have a project or if the project is not yet public, you can alternatively use your Github account URL.
  • SCM URL: this can be the same as your project URL.
  • Username(s): don’t bother with this if you are the sole owner of the namespace, otherwise add the JIRA usernames for anyone else you wish to grant access to.

The ticket will take 2–3 days to process. You can continue to the next steps, but do not deploy your project until you have received an email notice indicating that the above ticket has been Resolved!

Create your PGP signature

First install GPG here or via your favorite package manager. You can use gpg or gpg2. Verify that you have GPG installed via:

$ gpg --version
gpg (GnuPG) 1.4.18
Copyright (C) 2014 Free Software Foundation, Inc.

Then generate your key pair:

$ gpg --gen-key

Use the default suggestion for RSA and RSA key, the default 2048 keysize, expiration date of your own choosing (I chose 18m for mine). Input your name and email, and then for the optional comment you can further identify yourself (e.g. Android developer). The passphrase should be a secure and unique password that you can remember.

List your available keys using the following command:

$ gpg --list-keys
pub 2048R/XXXXXXXX 2016-12-01 [expires: ...]
uid Jin Cao (Android Dev) <jin@robinhood.com>
sub 2048R/YYYYYYYY 2016-12-01 [expires: ...]

Find the key that you just created (you can check the creation timestamp), copy the key value for pub which is signified by XXXXXXXX above. Now distribute the key to a key server using the following:

gpg --keyserver hkp://pool.sks-keyservers.net --send-keys XXXXXXX

One more thing that you have to do to publish your Android project with the maven script is to modify (or create if you don’t already have a file) your ~/.gradle/gradle.properties to add the following fields.

NEXUS_USERNAME=username that you registered for on Sonatype
NEXUS_PASSWORD=password for your Sonatype account
signing.keyId=XXXXXXXX your public key id that you used earlier
signing.password=your key paraphrase
signing.secretKeyRingFile=your key location, e.g. /Users/.../.gnupg/secring.gpg

Prepare your library for open source publishing

There are several things you need to do to your Android project to prepare it for open source and publishing to Maven.

  • Add LICENSE.txt to your library.
  • Add README.md to your library because documentation matters. Look up markdown syntax if you need help figuring out how to style your text.
  • Add CHANGELOG.md to your library because release documentation also matters.
  • Configure your gradle.properties to include the necessary fields as seen here.
  • Add Chris Banes’s maven push script to your library module. You can copy it from here because the original Github link seems to be no longer valid.
  • Add this line to the bottom of your library’s build.gradle.
apply from: ‘./gradle-mvn-push.gradle’

Publishing your library

Once you have everything ready in your library (should read up on best API practices and such for writing an Android library), there are a few steps that you have to do to publish it on Maven. Note that you should follow these steps whenever you push a new version for your library.

Shoutout to Square Engineering for contributing to the Android open source community and providing great documentations such as this one.

  • Update your gradle.properties to reflect the release VERSION_NAME. This should typically be 1.0.0 for initial public release.
  • Update your README.md to update the version code in the instructions.
  • Update your CHANGELOG.md to include the latest release and add release notes.
  • Tag the current commit with the release tag.
  • run ./gradlew clean uploadArchives in your project directory.
  • Go to the Nexus repository manager and log in with your Sonatypes credentials. Click on Staging Repositories on the left navigation bar. 

  • Find the project that you just uploaded and select it. This is typically on the bottom of the staging repositories list.
  • Click on the Close button on the top menu bar, add some description such as “version 1.0.0 ready for release”.
  • Wait a few moments, you can click on Refresh on top to check progress.
  • Eventually the repository will be closed, and the Release button on the top menu bar should be enabled. Click on Release to officially release your project artifacts on Maven! Note that releases can take a few hours to propagate before you can compile against it.
  • Once the release is complete, push out the changes that you made on your project with some commit message like “Preparing for 1.0.0 release” so others can see the updated documentation and tags.


That’s basically it! The setup might have been a bit confusing, but once you get through it, you can publish any number of libraries onto your Maven namespace to allow other developers see and use your code.


The Central Repository

Pushing AARs to Maven Central


Jinyan Cao  Jinyan Cao

Android Engineer @ Robinhood, occasionally blogs about Android stuff. Check out his Medium blog for more great tutorials and tips.

Related Search Term(s): maven

Create, Design, Develop and Connect at AnDevCon D.C. 2017!

Thoughts? Leave a comment: