In a previous post, I mentioned that the Android Contact Picker library is now deployed to maven central. Getting there was a multi-day process which involved a lot of Googling to figure out stuff. Thanks to blogs like this and this, I was able to finally get through the process. But it can be a bit tedious if you are new to all the side-processes involved.
For this reason, I want to document the whole process again for myself and maybe for anyone who might find it useful. I am doing a series about deploying to maven central, starting with preparing your POM file right up to final deployment. The basic assumption here is that you know your way around maven and are looking to deploy to Central.
As there are many ways to get to Maven Central, I am going to focus on using the Sonatype Express which takes only Open Source Software passengers. There is a guide to the Sonatype OSS Maven repository, which focuses on how to deal with things on their end. These series of posts focus on what you the developer need to do to prepare your artifacts for maven central.
This post will focus on the first step, which is preparing your POM file.
Part 1: Verify your luggage – Is your POM ready?
I am assuming you already use maven for building your project (hence the interest in deploying to maven central). This means you know what the pom.xml file is, and if you do not, take a look at the Complete Maven Reference and the POM reference. Maven can easily build your project with a minimum of information like the packaging, dependencies etc.
However, much more is needed in order to deploy your artifacts so that they can be reliably shared with others and dependencies properly resolved. There is a minimum set of tags required in the POM file in order to improve the central repository and support the Maven ecosystem. The minimum required tags are the following:
More details on each of the elements can be found in the POM reference. You can take a look at the Android Contact Picker POM file for an example of how to enter the attributes. Here are a few additional notes about some of the required elements in the POM:
- Choose your Maven coordinates carefully. They need to be unique to your project. Use your domain name or that of your organization as prefix. It is usually recommended, but not required that the coordinates match your Java package names.
- While still in the development phase, use the –SNAPSHOT suffix in your project version. For example <version>2.2.0-SNAPSHOT</version>. This enables you to always get the latest development build when testing.
- Version control links are important (and mandatory) and most popular versioning systems are supported by Maven. They will also be used during the final release phase by the maven-release-plugin.
- Putting the release repository/pluginRepository in your POM is discouraged. In ideal conditions, all your dependencies should be already in central and central repository is self-contained.
Once your pom file has all the necessary components in place you should test your build by running maven clean install. This will build your project and install it into your local maven repository. If this succeeds, then you are ready to go on to the next step. If not, look at the errors and fix any issues and rebuild. Rinse and repeat until it works.
The next stop en route to Maven Central and the topic of the next post is verifying your identity.
Photo credit: Steven Barker on Flickr