I am trying to setup jacoco
for my project\'s code coverage
My project is based on Java 1.8
Here is how things look in my project
Following works for me without any issues
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
NOTE : phase is 'test' in-order to generate the report once tests are executed
Any particular reason why you are using an outdated version of the JaCoCo plugin? For Java 8 support, you have to use at least version 0.7.0 (see changelog).
In your configuration, the report goal is bound to the verify phase, so running mvn test
won't generate any report because it does not run the verify phase (test phase comes before verify). You have to use mvn verify
to execute tests and generate the report.
The JaCoCo project provides example Maven configurations. You can try "this POM file for a JAR project runs JUnit tests under code coverage and creates a coverage report".
JaCoco Maven Plugin is overriding Surefire argLine, in case you also need to override argLine, be sure to keep argLine variable:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx1024M ${argLine}</argLine>
</configuration>
</plugin>
Note you can change this property name, as describe in the jacoco plugin documentation.
This worked for me:
mvn clean install
mvn site
Even though the minimum code coverage was not met and mvn clean install
failed, the mvn site
build succeeded and created the coverage report at:
.../target/site/jacoco/index.html