I'm trying to get rid of the following warning message:
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
It appears when executing Java (17) unit tests with Mockito through Maven (v3.9.2).
Based on the answers provided to this question and the initial comments in this Mockito GitHub issue, adding the JVM arg -Xshare:off
seemed to be the way to go. Unfortunately, this prevents JaCoCo to create an execution data file and thus prevents report to be generated based on it:
[INFO] --- jacoco:0.8.11:report (report-unit-tests) @ commons-test ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
So, this brings me with the following two questions:
The project is a multi-module one with the following setup:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<argLine>-Xshare:off</argLine>
<parallel>all</parallel>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<argLine>-Xshare:off</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Thanks to @khmarbaise, I found that @{argLine}
was required when configuring the JVM args. With this minor adjustment, I finally solved my issue!
Here is the final setup with surefire and failsafe Maven plugins:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<argLine>@{argLine} -Xshare:off</argLine>
<parallel>all</parallel>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<argLine>@{argLine} -Xshare:off</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
No more CDS warnings while keeping the coverage reports generated as expected!
More details can be found here.