I have setup Jacoco in my project to do a) check for the code coverage and b) produce a coverage report. The generated HTML report shows the right coverage values but the warning messages that Jacoco check generates at the end of the build process shows different and wrong values. I wonder what I'm doing wrong here.
For example here is what I can see for a util class in the generated HTML report:
but for the same class I see this when the build is finished:
Here is my jacoco-report config in my pom.xml file:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco.check</id>
<goals>
<goal>check</goal>
</goals>
<phase>${jacoco.check.phase}</phase>
<configuration>
<skip>${jacoco.skip}</skip>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>CLASS</element>
<excludes>
<exclude>com/xxxxxx/**/config/**/*</exclude>
<exclude>com/xxxxxx/**/filter/**/*</exclude>
<exclude>com/xxxxxx/xxxxxx/errors/*</exclude>
<exclude>com/xxxxxx/xxxxxx/security/*</exclude>
<exclude>com/xxxxxx/xxxxxx/xxxxxxOnlineWebApplication.class</exclude>
</excludes>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.90</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<propertyName>itCoverageAgent</propertyName>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
and my jacoco-check config is as follows:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPaths}</destFile>
</configuration>
</execution>
<!-- Integration-tests executed with failsafe-plugin -->
<execution>
<id>agent-for-it</id>
<phase>package</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.itReportPath}</destFile>
</configuration>
</execution>
</executions>
<configuration>
<excludes>
<exclude>com/xxxxxx/**/config/**/*</exclude>
<exclude>com/xxxxxx/**/filter/**/*</exclude>
<exclude>com/xxxxxx/xxxxxx/errors/*</exclude>
<exclude>com/xxxxxx/xxxxxx/security/*</exclude>
<exclude>com/xxxxxx/xxxxxx/xxxxxxOnlineWebApplication.class</exclude>
</excludes>
</configuration>
</plugin>
It looks like you are changing the location that the results are stored in:
<destFile>${sonar.jacoco.itReportPath}</destFile>
You will also need to tell the check plugin where to find the data file using the <dataFile>
item to your rules configuration.
Please see the jacoco:check docs for more information.