My belief is that JaCoCo Maven plugins check
goal does not support integration tests in a multi module project (where the integration tests are in a different module to the code under test).
I have a project with the following structure:
service
├── webapp
├── lib1
├── lib2
└── integration-test
webapp
depends on lib1
and lib2
and builds to a WAR, integration-test
uses an in memory container to run webapp
and execute tests against it.
My configuration is such that JaCoCo is successfully generating consolidated data files (jacoco.exec
and jacoco-it.exec
in service/target/
) for unit tests in {webapp
, lib1
, lib2
} AND integration test coverage for the tests run in integration-test
.
When adding in the configuration for check
I get this output from the plugin.
[INFO] --- jacoco-maven-plugin:0.7.8:check (default-check) @ integration-test ---
[INFO] Skipping JaCoCo execution due to missing classes directory:/home/mark/workspace/service/integration-test/target/classes
The error is accurate, as the integration-test
module has only test source, so there is no target/classes
directory. Adding a source directory didn't help, check
failed indicating 0% coverage because there was no applicable class files in the target/classes
directory.
From this (and looking at the check Mojo source) it seems the check
goal requires the classes
directories of all the modules that it is instrumenting (webapp
, lib1
, lib2
).
No such configuration exists in check
that allows me to specify where the classes
directories nor does it looks like it supports such a feature looking at the source.
Root / parent pom.xml
<properties>
<sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
<-- Note, I am using build/plugins/plugin - not build/pluginManagement/plugin
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
</configuration>
</execution>
<execution>
<id>agent-for-it</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.itReportPath}</destFile>
</configuration>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
<configuration>
<dataFile>${sonar.jacoco.itReportPath}</dataFile>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.9800</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
integration-test pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skipTests}</skipTests>
<argLine>${argLine} -Duser.timezone=UTC -Xms256m -Xmx256m</argLine>
<reuseForks>false</reuseForks>
</configuration>
</execution>
</executions>
</plugin>