Skip to content

Instantly share code, notes, and snippets.



Last active Feb 16, 2018
What would you like to do?
Testing Scala programs with Travis CI on OS X
language: java
- osx
- ./sbt "++$SCALA_VERSION" test
- env: SCALA_VERSION=2.11.7
os: linux
jdk: oraclejdk7
- env: SCALA_VERSION=2.10.5
os: linux
jdk: oraclejdk8

Testing Scala programs with Travis CI on OS X

Since a while ago, the fine folks at Travis CI offer OS X builds. Those machines also have Java installed, but just one version (1.7.0_45 at time of writing). The usual jdk_switcher mechanism is unavailable. Futhermore, Scala is not available. Luckily, it is possible to define a cross-platform (Linux and OS X) build within these constraints.

  1. Include @paulp's sbt launcher into the root of your repository. You can obtain a copy here. Alternatively, you can add an install step to your .travis.yml which fetches it before the build. (See the instructions in the README of sbt-extras.)
  2. Set the language entry in your .travis.yml to java.
  3. Remove the jdk and the scala entries.
  4. Instead, add a new top-level entry env which contains an item SCALA_VERSION=2.11.7 for each Scala version you want to test on.
  5. Add a new top-level entry os with the single item osx. It is important that it only contains osx and not linux.
  6. Add a new top-level entry matrix with sub-entry include. See the example file in this Gist for an idea what it should look like.

Real-world examples

Official documentation

For details on what exactly is available on the OS X boxes, see the official documentation.


This comment has been minimized.

Copy link

@muuki88 muuki88 commented Sep 3, 2017

Thanks for your integration into sbt native-packager and posting this here :)

I found an easier way that doesn't need a custom sbt launch script, but uses the
facilities provided by travis.

language: java
scala: 2.12.3
os: linux

  - if [[ "$TRAVIS_OS_NAME" = "osx" ]]; then
      brew update;
      brew install sbt;
script: sbt "$SBT_TEST_CMD";

# We explicitly set the matrix to include oraclejdk8 because MacOS X has issues. See comment below
    - jdk: oraclejdk8
      language: scala
      env: SBT_TEST_CMD="^validate"
      # oraclejdk8 is not yet available.
      # see
    - os: osx
      env: SBT_VERSION_CMD="^validate ^validateUniversal"
      osx_image: xcode8

sudo: false
 apt: true
 - $HOME/.sbt
 - $HOME/.ivy2

The core idea is to install sbt via brew and use java as a language and include the different steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment