Continuous integration for Scala

March 25, 2014

Here I outline the steps to take to enable continuous integration for Scala projects, including GitHub push-triggered building and testing, code test coverage, stats tracking, reporting, and badging.

Travis CI

First, enable basic continuous integration through Travis CI.

Under your travis-ci.org profile, find your project and enable it:

Enable your project on Travis CI
Enable your project on Travis CI

Create a .travis.yml file in the root of your project:

language: scala
scala:
  - 2.11.2

This gives you GitHub push-triggered builds (which run via sbt test) of your project, plus a sweet status badge.

Scoverage

Next, add code coverage support to your project with sbt-scoverage.

Import the sbt-scoverage plugin in your project configuration:

project/plugins.sbt:

addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "0.99.7.1")

Enable the sbt-scoverage plugin in your build configuration:

build.sbt:

ScoverageSbtPlugin.instrumentSettings

You can now run sbt scoverage:test from to get nice code coverage reports.

Coveralls

Now that you have triggered builds and code coverage, you can integrate with Coveralls to get integrated code coverage history and stats.

Head to the add repo section of Coveralls, find your project, and enable it:

Enable your project on Coveralls
Enable your project on Coveralls

Append script: "sbt coveralls" to your Travis CI configuration file:

.travis.yml:

language: scala
scala:
  - 2.10.3
script: "sbt coveralls"

Import the sbt-coveralls plugin in your project configuration:

project/plugins.sbt:

addSbtPlugin("com.sksamuel.scoverage" %% "sbt-coveralls" % "0.0.5")

Enable the sbt-coveralls plugin in your build configuration:

build.sbt:

CoverallsPlugin.coverallsSettings

This gives you coverage integration, plus a second status badge.