|
1 | 1 | # sbt-codacy-coverage
|
2 | 2 | [](https://www.codacy.com)
|
3 | 3 |
|
4 |
| -Sbt plugin for uploading Scala code coverage to Codacy https://www.codacy.com |
| 4 | +sbt plugin for uploading Scala code coverage to Codacy https://www.codacy.com |
| 5 | + |
| 6 | +``` |
| 7 | +sbt-codacy-coverage will only work with sbt 0.13.5 and higher. |
| 8 | +``` |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +Codacy assumes that coverage is previously configured for your project. As an example, we will configure a Scala project with the scoverage sbt plugin. |
| 13 | + |
| 14 | +To start, add the scoverage and Codacy sbt plugins into your plugins.sbt file: |
| 15 | + |
| 16 | +```sbt |
| 17 | +resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releases/" |
| 18 | + |
| 19 | +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.0.4") |
| 20 | + |
| 21 | +addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.0.3") |
| 22 | +``` |
| 23 | + |
| 24 | +Coverage should now be enabled for your project. |
| 25 | +To run the tests and create coverage files, type in your terminal: |
| 26 | + |
| 27 | +```sbt |
| 28 | +sbt clean coverage test |
| 29 | +``` |
| 30 | + |
| 31 | +This will create coverage reports for all your tests in your project. |
| 32 | +In order to export scoverage report files into cobertura compatible files, just type: |
| 33 | + |
| 34 | +```sbt |
| 35 | +sbt coverageReport |
| 36 | +``` |
| 37 | + |
| 38 | +This will create the required report format for the Codacy plugin to read. |
| 39 | +If you have sub-projects within your project, you will want to aggregate all reports into one by running: |
| 40 | + |
| 41 | +```sbt |
| 42 | +sbt coverageAggregate |
| 43 | +``` |
| 44 | + |
| 45 | +## Updating Codacy |
| 46 | + |
| 47 | +To update Codacy, you will need your project integration token. You can find the token in Project -> Settings -> Integrations -> Coverage. |
| 48 | + |
| 49 | +Then set it in your terminal, replacing %Project_Token% with your own token: |
| 50 | + |
| 51 | +```sbt |
| 52 | +export CODACY_PROJECT_TOKEN=%Project_Token% |
| 53 | +``` |
| 54 | + |
| 55 | +Next, simply run the Codacy sbt plugin. It will find the current commit and send all details to your project dashboard: |
| 56 | + |
| 57 | +``` |
| 58 | +sbt codacyCoverage |
| 59 | +``` |
| 60 | + |
| 61 | +## Configure your build server |
| 62 | + |
| 63 | +After setting up and testing the coverage, you're ready to setup your build server to automate your process. |
| 64 | +Simply replace the step used to run your tests with the process done so far, shown here for brevity sake: |
| 65 | + |
| 66 | +```sbt |
| 67 | +sbt clean coverage test |
| 68 | +sbt coverageReport |
| 69 | +sbt coverageAggregate |
| 70 | +sbt codacyCoverage |
| 71 | +``` |
| 72 | + |
| 73 | +## Failing tests |
| 74 | + |
| 75 | +Failing tests can be caused by the usage of macros in Scala 2.10. |
| 76 | +Consider upgrading to Scala 2.11 for full macro support. |
0 commit comments