Building a Scala project

What This Guide Covers

Language versions and other build-environment specific information are in our reference pages:

Scala builds are not available on the OS X environment.

The rest of this guide covers configuring Scala projects in Travis CI. If you’re new to Travis CI please read our Getting Started and build configuration guides first.

Overview

Travis CI environment provides a large set of build tools for JVM languages with multiple JDKs, Ant, Gradle, Maven and sbt.

Specifying Scala versions

To specify Scala versions in your build:

language: scala
scala:
   - 2.9.3
   - 2.10.4
   - 2.11.2

Projects using sbt

If your project has a project directory or build.sbt file in the repository root, the Travis CI uses sbt to build it.

Thanks to paulp/sbt-extras the sbt version of your project is dynamically detected and used.

sbt Dependency Management

Travis CI automatically pulls down sbt dependencies before running tests during the script phase of your build.

sbt Default Script Command

The default script command is:

sbt ++$TRAVIS_SCALA_VERSION test

to run your test suite.

To use a different script command, customize the build step.

Custom sbt Arguments

You can override sbt and JVM options by passing extra arguments to sbt.

For example, to run compile and test with different JVM parameters:

script:
  - sbt -jvm-opts travis/jvmopts.compile ... compile
  - sbt -jvm-opts travis/jvmopts.test ... test

You can also specify extra arguments to be passed to the default build script with the sbt_args key in your .travis.yml.

For example

sbt_args: -no-colors -J-Xss2m

will generate

script: sbt -no-colors -J-Xss2m ++$TRAVIS_SCALA_VERSION test

Projects Using Gradle, Maven or Ant

If your project is not configured for sbt, the build process behaves like a typical Java Project.

Testing Against Multiple JDKs

As for any JVM language, it is also possible to test against multiple JDKs.

Build Matrix

For Scala projects, env, scala, and jdk can be given as arrays to construct a build matrix.

Environment Variable

The version of Scala a job is using is available as:

TRAVIS_SCALA_VERSION

Examples