Maven surefire plugin problems with Jacoco, JMockit and JDK14

jacocojava-14jmockitmaven

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.

Best Answer

According to JaCoCo changelog (https://www.jacoco.org/jacoco/trunk/doc/changes.html) support for Java 14 class files was added in JaCoCo version 0.8.5, however latest as of today JMockit version 1.49 still does not fully support Java 11 bytecode - see an open ticket in JMockit https://github.com/jmockit/jmockit1/issues/615#issuecomment-501009439 :

JMockit should be fixed to properly handle condy (https://openjdk.java.net/jeps/309).

Related Topic