sbt plugin for uploading Scala code coverage to Codacy https://www.codacy.com
sbt-codacy-coverage will only work with:
- sbt 0.13.5 and higher
- Java JRE 7 and higher
Codacy assumes that coverage is previously configured for your project. As an example, we will configure a Scala project with the scoverage sbt plugin.
To start, add the scoverage and Codacy sbt plugins into your plugins.sbt file:
resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releases/"
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.4")Coverage should now be enabled for your project. To run the tests and create coverage files, type in your terminal:
sbt clean coverage testThis will create coverage reports for all your tests in your project. In order to export scoverage report files into cobertura compatible files, just type:
sbt coverageReportThis will create the required report format for the Codacy plugin to read. If you have sub-projects within your project, you will want to aggregate all reports into one by running:
sbt coverageAggregateTo update Codacy, you will need your project integration token. You can find the token in Project -> Settings -> Integrations -> Add Integration -> Project API.
Then set it in your terminal, replacing %Project_Token% with your own token:
export CODACY_PROJECT_TOKEN=%Project_Token%Note: You should keep your API token well protected, as it grants owner permissions to your projects.
Next, simply run the Codacy sbt plugin. It will find the current commit and send all details to your project dashboard:
sbt codacyCoverage
Note: To send coverage in the enterprise version you should:
export CODACY_API_BASE_URL=<Codacy_instance_URL>:16006
After setting up and testing the coverage, you're ready to setup your build server to automate your process. Simply replace the step used to run your tests with the process done so far, shown here for brevity sake:
sbt clean coverage test
sbt coverageReport
sbt coverageAggregate
sbt codacyCoverageFailing tests can be caused by the usage of macros in Scala 2.10. Consider upgrading to Scala 2.11 for full macro support.
Due to a limitation in Java 6, the plugin is unable to establish a connection to codacy.com.
You can run this script after sbt codacyCoverage to upload the generated report to Codacy.
Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.
- Identify new Static Analysis issues
- Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
- Auto-comments on Commits and Pull Requests
- Integrations with Slack, HipChat, Jira, YouTrack
- Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories
Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.
Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.
Codacy is free for Open Source projects.