This blog has been migrated to GitHub Pages. See you there:
April 13, 2017
As an exercise in creating a Java library and submitting it to the Central Repository, I created an implementation of the xirr (irregular internal rate of return) function in Java.
If you are interested in what needs to be done to publish to the Maven Central Repository, check out the pom.xml for starters. The
distributionManagement section contains configuration for pointing to the Nexus Repository Manager at oss.sonatype.org. This Nexus installation is used as a staging platform for the Central Repository.
Next in the
plugins section we include the
maven-javadoc-plugin in order to generate the source and javadoc jars for the repository. Your library will not be accepted without these.
Next there is the
maven-gpg-plugin for generating signature files for the artifacts. In order to generate the signature files, you will need to have a GPG key and placed the public key on a keyserver. If you don't have this already, google for some GPG tutorials. More about this in a moment.
Finally in the
pom.xml we have the
nexus-staging-maven-plugin plugin configuration. This plugin overrides the standard deploy plugin to interact with the Nexus Repository Manager.
Both the oss.sonatype.org and the GPG key have authentication credentials which need to be managed as part of the build process. To begin, you need to create a maven master password if you have not already done so. If you are not sure, look for the
~/.m2/settings-security.xml file to see if it has a
master element. All the passwords for maven configuration can be encrypted. To generate an encrypted master password, issue the command
mvn --encrypt-master-password and then place the result in your
Then you need to encrypt your passwords using
mvn --encrypt-password and put them in your
Note that the first
server id corresponds with the
id in the
distributionManagement section of the
pom.xml. The second
server id is used by the
maven-gpg-plugin by default. Of course that can be changed by configuration, see the documentation of that plugin for details.