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
- The JaCoCo distribution contains a simple example how code coverage can be added to a Maven project.
- This POM file for a JAR project runs JUnit tests under code coverage and creates a coverage report (target/site/jacoco/index.html).
- This POM file for a JAR project runs unit tests and integration tests under code coverage and creates two coverage reports, one for unit tests ( target/site/jacoco/index.html) and one for integration tests ( target/site/jacoco-it/index.html).
-
The complete example is located in the
./doc/examples/build
folder of the distribution.
Prerequisites
The JaCoCo Maven plug-in requires
- Maven 2.1.0 or higher and
- Java 1.5 or higher (for both, the Maven runtime and the test executor).
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>@project.version@</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: