archived-codacy / sbt-codacy-coverage   3.0.3

GitHub

Sbt plugin for uploading Scala code coverage to Codacy https://www.codacy.com

Scala versions: 2.12 2.10
sbt plugins: 1.x 0.13

Deprecated

This repository is no longer maintained. As an alternative, check codacy-coverage-reporter to send your test coverage results to your Codacy dashboard.

sbt-codacy-coverage

Codacy Badge Circle CI Maven Central

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

Setup

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.5.1")

addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "<latest-version>")

Check latest version in https://maven-badges.herokuapp.com/maven-central/com.codacy/sbt-codacy-coverage

Coverage should now be enabled for your project. To run the tests and create coverage files, type in your terminal:

sbt clean coverage test

This 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 coverageReport

This 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 coverageAggregate

Updating Codacy

To 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

CommitUUID Detection

Codacy automatically detects the CommitUUID from several sources:

Environment Variables

  • CI_COMMIT
  • TRAVIS_PULL_REQUEST_SHA
  • TRAVIS_COMMIT
  • DRONE_COMMIT
  • CIRCLE_SHA1
  • CI_COMMIT_ID
  • WERCKER_GIT_COMMIT

Git directory

  • If it finds a git directory it will get current commit.

Force CommitUUID

  • You may want to enforce a specific commitUUID with:
sbt 'set codacyCommit := "mycommituuid"' codacyCoverage

Configure your build server

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 codacyCoverage

Failing tests

Failing tests can be caused by the usage of macros in Scala 2.10. Consider upgrading to Scala 2.11 for full macro support.

Troubleshooting

  1. Builds from forks are failing on Coverage?

If you are using an automated CI that also runs builds from forks but does not have access to the project token to send coverage you should protect the coverage step in your configuration to avoid the build failure.

  1. Failing to send coverage

Message: Failed to upload data. Reason: not found

This issue is usually related to bad authentication. Make sure you are using the correct token. Most time you will want to use the Project API Token as described in Updating Codacy.

If you decide to use the Account API Token, you will need to provide extra details about your project. You need to make sure to provide the project owner username and the project name on Codacy as part of the identification when pushing coverage.

Example

if [[ -n "$CODACY_PROJECT_TOKEN" ]]; then sbt codacyCoverage; else echo "Skipped coverage reporting since no token was found"; fi

Java 6

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.

What is 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.

Among Codacy’s features:

  • 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.

Free for Open Source

Codacy is free for Open Source projects.