I am unable to get the code coverage in Java 11 for Powermock tests using Jacoco maven plugin. My version details are as below:
Java version: jdk-11.0.2
Maven version: maven 3.5.2
Jacoco maven plugin version: 0.8.5
Powermock version: 2.0.0-beta.5
I have also added the jacoco runtime agent as we are supposed to in the classpath of all the subprojects:
<dependencies>
<!-- Added to provide jacocoagent in classpaths for offline instrumentation builds
Refer https://www.jacoco.org/jacoco/trunk/doc/offline.html -->
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<scope>test</scope>
<version>${jacoco.plugin.version}</version>
</dependency>
</dependencies>
These are my plugin details (Please note that these settings work absolutely fine in Java 8):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Skips unit tests if the value of skipTests property is true -->
<skipTests>${skipTests}</skipTests>
<!-- Excludes integration tests when unit tests are run -->
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<append>true</append>
<destFile>${user.dir}/target/jacoco.exec</destFile>
<excludes>
<exclude>*</exclude>
</excludes>
<dataFile>${user.dir}/target/jacoco.exec</dataFile>
<outputDirectory>${user.dir}/target/coverage-reports/jacoco</outputDirectory>
</configuration>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Result:
[INFO] --- jacoco-maven-plugin:0.8.5:instrument (default-instrument) @ utils ---
[WARNING] The POM for org.codehaus.plexus:plexus-utils:jar:1.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.5:restore-instrumented-classes (default-restore-instrumented-classes) @ utils ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.5:report (jacoco-site) @ utils ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
As you can see the jacoco.exec file is not being generated in case of offline instrumentation.
Please note that I am able to generate jacoco.exec file when I am not using offline instrumentation (i.e. using the prepare-agent goal) however it ignores the PowerMock tests.
As per this issue: https://github.com/jacoco/jacoco/issues/663
Support for Java 11 has been provided in version 0.8.3 however I am not sure if any changes were made in the offline instrumentation that is causing any issue.
Please advise if anything else is required from my end.