SBT plugin that uploads scala code coverage to https://coveralls.io and integrates with Travis CI. This plugin uses scoverage to generate the code coverage metrics.
For an example project that uses this plugin click here. For example output click here
- Add the following to your
project/build.sbt
file
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")
-
Setup coveralls configuration options (such as Specifying Your Repo Token)
-
Register on
https://coveralls.io/
-
Follow the instructions for either Travis CI or Manual Usage
sbt-coveralls
can be run by Travis CI by following these instructions:
-
Add the following to your
travis.yml
script: "sbt clean coverage test" after_success: "sbt coverageReport coveralls"
If you have a multi-module project, perform
coverageAggregate
as a separate commandscript: - sbt clean coverage test coverageReport && sbt coverageAggregate after_success: - sbt coveralls
-
Job done! Commit these changes to
travis.yml
to kick off your Travis build and you should see coverage reports appear on https://coveralls.io/
-
Get the repo token for your repo from http://coveralls.io
-
Let
sbt-coveralls
know what your coveralls repo token is. See Specifying Your Repo Token -
In the SBT console, run
coverage
then your tests finishing withcoveralls
. After running the command, you should see output similar to the following:Uploading to coveralls.io succeeded: Job #17.1 https://coveralls.io/jobs/12207
For example output click here
There are several ways to tell sbt-coveralls
your repo token to support different use cases:
Add the following to your build.sbt
. The path can be absolute and point to somewhere outside the project or relative and point somewhere inside the project (such as src/main/resources/token.txt
).
Just remember: Do not store repo tokens inside your project if it is in a public git repository!
import org.scoverage.coveralls.Imports.CoverallsKeys._
coverallsTokenFile := "/path/to/my/repo/token.txt"
Do not store repo tokens inside your project if it is in a public git repository!
import org.scoverage.coveralls.Imports.CoverallsKeys._
coverallsToken := Some("my-token")
Add an environment variable COVERALLS_REPO_TOKEN
, for example:
export COVERALLS_REPO_TOKEN=my-token
If you're using https://coveralls.io as your endpoint, then you don't need to set this option. If you're using a hosted (enterprise) instance of coveralls, you will need to specify your endpoint in one of two ways.
import org.scoverage.coveralls.Imports.CoverallsKeys._
coverallsEndpoint := Some("http://my-instance.com")
Add an environment variable COVERALLS_ENDPOINT
, for example:
export COVERALLS_ENDPOINT=http://my-instance.com
By default sbt-coveralls
uses the currently checked-out branch for reporting. To override the branch name add the CI_BRANCH
variable, for example:
export CI_BRANCH=my-branch-name
sbt-coveralls
finds the encoding in scalacOptions
setting value.
If not defined it assumes source files are encoded using platform-specific encoding.
To specify encoding, add the following to your build.sbt
scalacOptions += Seq("-encoding", "UTF-8")
It is important to set the correct service_name
when using Travis-Pro. The default is to use travis-ci
. To override this value, add the following to your build.sbt
import org.scoverage.coveralls.Imports.CoverallsKeys._
coverallsServiceName := Some("travis-pro")
sbt-coveralls
is open source software released under the Apache 2 License.