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 

  1. Nexus Account - request one by creating a help desk ticket at https://help.openmrs.org/

  2. 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>
  1. 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

  1. Run `mvn clean deploy` to test the configuration of the snapshots deployment

  2. 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


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



NOTE: You need to encrypt the username and password for each repository, as the encrypted values are repository specific 

Related articles