This blog post will show the steps required to deploy a maven artifact on Maven central using Travis CI.
To deploy an artifact to maven artifact to Maven central we need a lot of preparations before we can actually deploy an artifact.
1. Create a Sonatype account
Sonatype provides free access to Maven central. With an account you can access their Nexus and deploy your artifacts in their repository which is synced to Maven central.
The guide about setting up an “OSSRH” account can be found here.
Basically the sign up process contains the following steps:
- Create a JIRA account
- Choose a Maven
groupId
- Create a JIRA issue to gain access to the
groupId
- Wait for approvement
2. Create a GPG key
Ensure that you’re using a GPG v1 executable (you can check that with gpg --version
).
This is required because the GPG binary on Travis CI does not support the encrypted keys of GPG v2.
Add the private key to your Git repository. No fear, it is encrypted with your passphrase, no one can decrypt it.
3. Configure your Maven build
To successfully deploy a Maven artifact you have to meet the following constraints:
Add required information to the pom.xml
A Maven artifact has to provide serveral informations to be allowed for deploy in the central repository. You can find those details here.
Add a release profile to the pom.xml
Add the following lines to your pom.xml
of the to be deployed artifact.
It is required to generate a source jar, a javadoc jar and sign all jar files.
The fourth plugin is used to automatically deploy to the Sonatype Nexus Repository.
Create a Maven settings.xml
We have to use a settings.xml
to provide Maven the required Sonatype user and
password and the passphrase for you gpg key.
Add it to your Git repository.
4. Setup the Travis build
Encrypt your Sonatype credentials and gpg key passphrase
You must use the Travis CLI to encrypt your credentials required to authenticate and sign your build.
The resulting encrypted strings you’ve to add in the next step.
Add a .travis.yml
file to your git repository
This file is used for travis to build and deploy your project.
Add a Makefile to build your Maven artifact
You have to change the paths to your gpg private-key and your Maven settings.xml
.
5. Test the build process
When you push something or a pull request is created the project is automatically
built using make build
. When you create a tag for the repository it will
automatically deploy an artifact to the Maven central repository with the version
set to the tag name.