Skip to content
This documentation applies to Codacy Self-hosted v3.4.0

For the latest updates and improvements, see the latest Cloud documentation instead.

Alternative ways of running Coverage Reporter

The recommended way to run Codacy Coverage Reporter is using a self-contained script that automatically downloads and runs the most recent version of Codacy Coverage Reporter:

  • On Ubuntu, run:

    bash <(curl -Ls https://coverage.codacy.com/get.sh)
    
  • On Alpine Linux, run:

    wget -qO - https://coverage.codacy.com/get.sh | sh
    

The self-contained script can cache the binary. To avoid downloading the binary every time that the script runs, add one of the following directories to your CI cached folders:

  • $HOME/.cache/codacy on Linux
  • $HOME/Library/Caches/Codacy on Mac OS X

To use a specific version of the Codacy Coverage Reporter, set the following environment variable to one of the released versions:

export CODACY_REPORTER_VERSION=<version>

The sections below provide details on alternative ways to run or install Codacy Coverage Reporter.

Docker

You can use Docker to run Codacy Coverage Reporter:

docker run -v $PWD:/code codacy/codacy-coverage-reporter:<version> report

Manually downloading the binary

Linux amd64

If you prefer, you can manually download and run the native codacy-coverage-reporter binary, either for the latest version or a specific one.

You can use the scripts below to automatically check for the latest version of the binaries, download the binaries from either Codacy's public store or GitHub, and run them.

  • Using Codacy's public S3:

    LATEST_VERSION="$(curl -Ls https://artifacts.codacy.com/binaries/codacy-coverage-reporter/latest)"
    curl -Ls -o codacy-coverage-reporter "https://artifacts.codacy.com/binaries/codacy-coverage-reporter/${LATEST_VERSION}/codacy-coverage-reporter-linux"
    chmod +x codacy-coverage-reporter
    ./codacy-coverage-reporter report
    
  • Using GitHub:

    curl -Ls -o codacy-coverage-reporter "$(curl -Ls https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({name, browser_download_url} | select(.name | contains("codacy-coverage-reporter-linux"))) | .[0].browser_download_url')"
    chmod +x codacy-coverage-reporter
    ./codacy-coverage-reporter report
    

Java

Use the Java binary to run Codacy Coverage reporter on other platforms, such as Linux x86, macOS, Windows, etc.

You can use the scripts below to automatically check for the latest version of the Java binaries, download the binaries from either Codacy's public store or GitHub, and run them.

  • Using Codacy's public store:

    LATEST_VERSION="$(curl -Ls https://artifacts.codacy.com/bin/codacy-coverage-reporter/latest)"
    curl -Ls -o codacy-coverage-reporter-assembly.jar "https://artifacts.codacy.com/bin/codacy-coverage-reporter/${LATEST_VERSION}/codacy-coverage-reporter-assembly.jar"
    java -jar codacy-coverage-reporter-assembly.jar report
    
  • Using GitHub:

    curl -LS -o codacy-coverage-reporter-assembly.jar "$(curl -LSs https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({name, browser_download_url} | select(.name | endswith(".jar"))) | .[0].browser_download_url')"
    java -jar codacy-coverage-reporter-assembly.jar report
    

Building from source

If you are having any issues with your installation, you can also build the coverage reporter from source.

  1. Clone the Codacy Coverage Reporter repository:

    git clone https://github.com/codacy/codacy-coverage-reporter.git
    
  2. Run the command sbt assembly inside the local repository folder:

    cd codacy-coverage-reporter
    sbt assembly
    

    This will produce a file target/codacy-coverage-reporter-assembly-<version>.jar that you can run.

  3. Execute this .jar in the repository where you want to upload the coverage. For example:

    <path>/java-project$ java -jar ../codacy-coverage-reporter/target/codacy-coverage-reporter-assembly-<version>.jar report
    

CircleCI orb

If you are using CircleCI to report coverage, you can use our orb codacy/coverage-reporter.

GitHub Action

If you are using GitHub Actions to report coverage, you can use our GitHub Action codacy/codacy-coverage-reporter-action.

Community supported alternatives

Maven plugin

Thanks to the amazing job of Gavin Mogan you can now send your coverage to Codacy using his Maven plugin halkeye/codacy-maven-plugin! Be sure to follow the instructions on his repository.

Travis CI

If you are using Travis CI to report coverage, update your file .travis.yml to include the following blocks:

before_script:
  - bash <(curl -Ls https://coverage.codacy.com/get.sh) download

after_success:
  - bash <(curl -Ls https://coverage.codacy.com/get.sh)

Make sure that you also set your project API Token as an environment variable in your Travis CI job.

Gradle task

A big shout-out to Tom Howard, who suggested a way to create a Gradle task.

task uploadCoverageToCodacy(type: JavaExec, dependsOn : jacocoTestReport) {
   main = "com.codacy.CodacyCoverageReporter"
   classpath = configurations.codacy
   args = [
            "report",
            "-l",
            "Java",
            "-r",
            "${buildDir}/test-results/jacoco/${archivesBaseName}.xml"
           ]
}

task (codacyDepsize) << {
def size = 0;
configurations.codacy.collect { it.length() / (1024 * 1024) }.each { size += it }
println "Total dependencies size: ${Math.round(size * 100) / 100} Mb"

configurations
        .codacy
        .sort { -it.length() }
        .each { println "${it.name} : ${Math.round(it.length() / (1024) * 100) / 100} kb" }
}

task (codacyLocs) << {
    configurations.codacy.each {
        String jarName = it
        println jarName
    }
}

The following Gradle task by Ramil Khamitov was based on the solution above.

configurations { codacy }
repositories {
    jcenter()
}
dependencies {
    codacy 'com.codacy:codacy-coverage-reporter:latest.release'
}
task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
    main = "com.codacy.CodacyCoverageReporter"
    classpath = configurations.codacy
    args = [
            "report",
            "-l",
            "Java",
            "-r",
            "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
    ]
}

Share your feedback 📢

Did this page help you?

Thanks for the feedback! Is there anything else you'd like to tell us about this page?

We're sorry to hear that. Please let us know what we can improve:

Alternatively, you can create a more detailed issue on our GitHub repository.

Thanks for helping improve the Codacy documentation.

If you have a question or need help please contact support@codacy.com.

Last modified March 5, 2021