Maven Plug-in

The JaCoCo Maven plug-in provides the JaCoCo runtime agent to your tests and allows basic report creation.

If you want to have line number information included in the coverage reports or you want source code highlighting the class files of the test target must be compiled with debug information.

When using the maven-surefire-plugin or maven-failsafe-plugin you must not use a forkCount of 0 or set the forkMode to never as this would prevent the execution of the tests with the javaagent set and no coverage would be recorded.

Example

Prerequisites

The JaCoCo Maven plug-in requires

Usage

The Maven plug-in can be included in your build with the following declaration. Please check here for the latest release version in the repository.

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.13-SNAPSHOT</version>
</plugin>

To receive a full list of goals and available parameters you can use maven-help-plugin:

mvn help:describe -Dplugin=org.jacoco:jacoco-maven-plugin -Ddetail

Usage of plugin together with maven-site-plugin without explicit selection of reports might lead to generation of redundant aggregate reports. Specify reportSets explicitly to avoid this:

<project>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <reportSets>
          <reportSet>
            <reports>
              <!-- select non-aggregate reports -->
              <report>report</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>
</project>

Goals

The JaCoCo Maven plug-in defines the following goals: