Travis is a continuous integration service used to build and test software projects hosted at GitHub. Travis is configured by adding a file named .travis.yml
which is a YAML format file in the root directory of the repository. Here we have the most basic example:
language: java
jdk: openjdk8
Travis environment contains various versions of Java (Open JDK, Oracle JDK), Gradle and Maven. Travis will search for a pom.xml
or build.gradle
file in order to use Maven or Gradle. Now for linking your GitHub account with Travis account, please follow this steps:
- Go to Travis-ci.com and sign up with GitHub.
- Accept the Authorization of Travis. You’ll be redirected to GitHub.
- Click the green Activate button, and select the repositories you want to use with Travis CI
In that way when you push a branch to your repository Travis will execute this steps:
- Will clone your GitHub repository
gradle assemble
gradle check
gradle test
If previous tasks were successfully executed will generate a build success status:
With Travis CI you can also do this tasks:
- Run JaCoCo code coverage and fail the build if desired percentage is not met
- Run Sonarqube code quality checks
- Built Docker image and publish it
Sonarqube Configuration
In order to add Sonarqube you need to add this plugin to your build.gradle
file:
plugins {
id "org.sonarqube" version "2.7"
}
Next step is to set three environment variables in your Travis project configuration:
- SONAR_LOGIN
- SONAR_PROJECT
Sonar login is an user token: In your Sonarqube account go to User>My Account>Security
Your existing tokens are listed there. Sonar project is your Project Key defined in the Sonar project main section.
Finally in your .travis.yml
file you need to add the command required to start Sonarqube scanner process
language: java
jdk: openjdk8
script:
- ./gradlew test sonarqube
Do not forget to add Sonar server url to your gradle.properties
file
systemProp.sonar.host.url=https://sonar.josdem.io/
You also can specify Sonar server from command line:
gradle test sonarqube -Dsonar.host.url=https://sonar.josdem.io
To browse a project using Travis configuration go here.