Maven surefire plugin problems with Jacoco, JMockit and JDK14

Viewed 11077

I tried to upgrade my project from JDK 11 to JDK 14, but running the tests failed after setting the java version to 14. As I am using jacoco in combination with JMockit I configured my build as follows (edit: JaCoCo version is 0.8.3 / 0.8.5, JMockit version 1.49):

    <build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${version.jacoco}</version>
            <executions>
                <execution>
                    <id>coverage-initialize</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>coverage-report</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${version.surefire-plugin}</version>
            <configuration>
                <argLine>
                    @{argLine} -javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${version.jmockit}/jmockit-${version.jmockit}.jar
                </argLine>
            </configuration>
        </plugin>
...

If I run maven with Java Version set to 11, everything works fine, but when I set the Java Version to 14 the surefire plugin throws this error:

[ERROR] java.lang.instrument.IllegalClassFormatException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
[ERROR]         at org.jacoco.agent.rt.internal_1f1cc91.CoverageTransformer.transform(CoverageTransformer.java:93)
[ERROR] sun.util.locale.provider.LocaleDataMetaInfo: Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo
[ERROR]         at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
[ERROR]         at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
[ERROR]         at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
[ERROR]         at java.base/java.lang.ClassLoader.defineClass2(Native Method)
[ERROR]         at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1109)

I tracked down the problem to the @{argLine} in the configuration of the surefire argline. If I remove this, the build runs just fine. Unfortunately this configuration is needed by JaCoCo. Without it it doesn't produce any reports.

Any suggestions?

Addendum: Just figured out, that the tests fail when running with JDK14. It does not depend on the compile version set in the pom.

3 Answers

For those not urgently needing the bells and whistles of JDK14+, only upgrading to JDK13 may prevent this problem from happening.

Related