SBT plugin that uploads scala code coverage to https://coveralls.io and integrates with Travis CI. This plugin uses either scoverage or SCCT to generate the code coverage metrics. This repo is a fork of the original xsbt-coverall-plugin to add support for scoverage. Use this project if you need scoverage support and until/if scoverage is supported upstream in xsbt-coveralls-plugin.
For an example project that uses this plugin click here. For example output click here
- Add the following to your
project/build.sbt
file
resolvers += Classpaths.sbtPluginReleases
addSbtPlugin("com.sksamuel.scoverage" % "sbt-scoverage" % "0.95.1")
addSbtPlugin("com.sksamuel.scoverage" %% "sbt-coveralls" % "0.0.5")
- Import the settings in your build file
Add the following to the top of your build.sbt
:
ScoverageSbtPlugin.instrumentSettings
CoverallsPlugin.coverallsSettings
Import the plugin settings, and add them to your project settings (example):
import scoverage.ScoverageSbtPlugin.instrumentSettings
import com.github.theon.coveralls.CoverallsPlugin.coverallsSettings
...
lazy val project = Project(
...
settings = defaultSettings ++ intsrumentSettings ++ coverallsSettings
)
Coveralls configuration options (such as Specifying Your Repo Token) must come after this line.
-
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 you
travis.yml
script: "sbt coveralls"
-
Job done! Commit these changes to
travis.yml
to kick off your Travis build and you should see coverage reports appear on http://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 the command
coveralls
. This should run your test suite, generate code coverage reports and upload the reports tocoveralls.io
. 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 CoverallsPlugin.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 CoverallsPlugin.CoverallsKeys._
coverallsToken := "my-token"
Add an environment variable COVERALLS_REPO_TOKEN
, for example:
export COVERALLS_REPO_TOKEN=my-token
By default sbt-coveralls
assumes your source files are UTF-8
encoded. To use a different encoding, add the following to your build.sbt
import CoverallsPlugin.CoverallsKeys._
encoding := "ISO-8859-1"
Once the plugin has slurped your source code into memory using the specified encoding, it will be converted into UTF-8 to be sent to the coveralls API. This is because the coveralls API uses a JSON request body and RFC 4627 mandates that JSON must be UTF encoded.
sbt-coveralls
is open source software released under the Apache 2 License.