Setup Travis CI to Deploy Snapshots to Nexus
While developing custom modules it is important to deploy the latest versions of snapshots to Nexus on commits to the master branch and merging of pull requests.
Prerequisites
Nexus Account - request one by creating a help desk ticket at https://help.openmrs.org/
Maven setup - a sample configuration is below
Sample maven settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<localRepository>${user.home}/.m2/repository</localRepository>
<servers>
<server>
<username>{nexus_username}</username>
<password>{nexus_password}</password>
<id>openmrs-repo</id>
</server>
<server>
<username>{nexus_username}</username>
<password>{nexus_password}</password>
<id>openmrs-repo-releases</id>
</server>
<server>
<username>{nexus_username}</username>
<password>{nexus_password}</password>
<id>openmrs-repo-snapshots</id>
</server>
<server>
<username>{nexus_username}</username>
<password>{nexus_password}</password>
<id>openmrs-repo-modules</id>
</server>
</servers>
<profiles>
<profile>
<properties>
<archetypeRepository>http://mavenrepo.openmrs.org/nexus/content/repositories/public</archetypeRepository>
<archetypeCatalog>http://mavenrepo.openmrs.org/nexus/content/repositories/public/archetype-catalog.xml</archetypeCatalog>
</properties>
<repositories>
<repository>
<id>openmrs-repo</id>
<name>OpenMRS Nexus Repository</name>
<url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
</repository>
<repository>
<id>openmrs-repo-thirdparty</id>
<name>OpenMRS Thirdparty Nexus Repository</name>
<url>http://mavenrepo.openmrs.org/nexus/content/repositories/thirdparty</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>openmrs-repo</id>
<name>OpenMRS Nexus Repository</name>
<url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
</pluginRepository>
</pluginRepositories>
<id>openmrs</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>openmrs</activeProfile>
</activeProfiles>
<pluginGroups>
<pluginGroup>org.openmrs.maven.plugins</pluginGroup>
</pluginGroups>
</settings>
Project distribution management in the module pom.xml
Distribution management in pom.xml
<distributionManagement>
<repository>
<id>openmrs-repo-modules</id>
<name>OpenMRS Modules</name>
<url>http://mavenrepo.openmrs.org/nexus/content/repositories/modules</url>
</repository>
<snapshotRepository>
<id>openmrs-repo-snapshots</id>
<name>OpenMRS Snapshots</name>
<url>http://mavenrepo.openmrs.org/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
Step-by-step guide
Run `mvn clean deploy` to test the configuration of the snapshots deployment
Add .travis.yml and maven-settings.xml files below to the root of your project
maven-settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>openmrs-repo-snapshots</id>
<username>${env.OPENMRS_REPO_USERNAME}</username>
<password>${env.OPENMRS_REPO_PASSWORD}</password>
</server>
</servers>
</settings>
.travis.yml
before_install: "git clone -b travis `git config --get remote.origin.url` target/travis"
after_script: "mvn deploy --settings target/travis/settings.xml"
language: java
branches:
except:
- travis
jdk:
- openjdk7
- oraclejdk7
script: mvn clean install --batch-mode
matrix:
allow_failures:
jdk: oraclejdk7
env:
global:
Add encrypted versions of the nexus username and password to the .travis.yml by executing the commands below at the root of your project
Encrypt Travis variables
travis encrypt OPENMRS_REPO_USERNAME=nexus_username --add env.global
travis encrypt OPENMRS_REPO_PASSWORD=nexus_password --add env.global
NOTE: You need to encrypt the username and password for each repository, as the encrypted values are repository specific