I am fairly new to JaCoCo and I am having trouble generating my code coverage report.
This is my project structure:
My integration tests live within the "...-integration-tests" module. When I build my project using mvn I get the following in my logging:
[INFO] Skipping JaCoCo execution due to missing classes directory: ...-integration-tests\target\classes
This is true because my compiled code is only available in the target>classes of the corresponding module.
What is the best way to make this working? Thanks in advance!
This happens because JaCoCo "report" mojo is trying to find sources and classes in "default" maven project layout:
@Override
boolean canGenerateReportRegardingClassesDirectory() {
return new File(getProject().getBuild().getOutputDirectory()).exists();
}
Having layout similar to yours I was able to circumvent JaCoCo configuration limitations by explicitly setting build.sourceDirectory and build.outputDirectory to point on internals of your tested module. After that maven tried to compile it for second time, so I've also had to override default compile execution, important (and shareable) part of my Tests module pom.xml now look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project ...
...
<parent>
...
</parent>
<dependencies>
...
</dependencies>
<properties>
...
</properties>
<build>
<sourceDirectory>../../Source</sourceDirectory> <!-- tested sources root, in proper layout: src/main/java -->
<outputDirectory>../bin</outputDirectory> <!-- tested classes root, in proper layout: target/classes -->
<testSourceDirectory>${project.basedir}/../../Test/java</testSourceDirectory> <!-- if tests code also taken from outside -->
<testResources>
...
</testResources>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<!-- disabling default-compile -->
<execution>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
<configuration>
<source>1.7</source>
<target>1.7</target>
<includes/>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</configuration>
</execution>
...
</executions>
</plugin>
<!-- typical jacoco usage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.10</version>
</dependency>
</dependencies>
<configuration>
...
<argLine>${argLine} -XX:PermSize=512M -XX:MaxPermSize=512M -Xmx1024M</argLine>
...
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
</configuration>
<executions>
...
</executions>
</plugin>
</plugins>
</build>
</project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With