Search code examples
command-line-interfacecode-coveragejacocojacoco-maven-plugin

How to create Jacoco code coverage report from jacoco.exec binary file that is generated from JAR file?


I have been looking to generate a code coverage report from the jar build file, with jacoco.

I found this command

java -jar jacococli.jar dump [--address <address>] --destfile <path> [--help] [--port <port>] [--quiet] [--reset] [--retry <count>]

to make it work but have no idea how to generate jacococli.jar .
I normally added as dependency but nothing happened.

<dependencies>
  <dependency>
    <groupId>org.jacoco</groupId>
    <artifactId>org.jacoco.cli</artifactId>
    <version>0.8.3</version>
</dependency>
</dependencies>

Solution

  • I found this command

    java -jar jacococli.jar dump [--address <address>] --destfile <path> [--help] [--port <port>] [--quiet] [--reset] [--retry <count>]
    

    ... added as dependecy but nothing happened

    jacococli.jar is not intended to be used as a dependency - command is shown in JaCoCo documentation on page https://www.jacoco.org/jacoco/trunk/doc/cli.html which states

    JaCoCo comes with a command line interface to perform basic operations from the command line.

    and later also states

    For more sophisticated usage especially with larger projects please use our integrations with various build tools.

    among integrations there is jacoco-maven-plugin for generation of report using Maven, documentation of this plugin available on page https://www.jacoco.org/jacoco/trunk/doc/maven.html


    To use jacococli.jar for generation of report from jacoco.exec file for your.jar file

    1. download zip distribution of JaCoCo from https://www.jacoco.org/jacoco/
    2. extract it for example into directory jacoco, jacococli.jar will be in jacoco/lib/jacococli.jar
    3. open command line in this directory and execute
    java -jar lib/jacococli.jar report path/to/jacoco.exec --classfiles path/to/your.jar --html path/for/report
    
    1. HTML report will be in directory path/for/report