JDK-13 Unsupported class file major version for surefire plugin
Asked Answered
B

2

7

I'm trying to create Java module project with Java-13 and Maven. My pom.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>wtf.g4s8</groupId>
  <artifactId>oot</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <properties>
    <junit-platform.version>5.3.1</junit-platform.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jdk.version>13</jdk.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest</artifactId>
      <version>2.1</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit-platform.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${junit-platform.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <target>${jdk.version}</target>
          <source>${jdk.version}</source>
          <release>${jdk.version}</release>
          <useIncrementalCompilation>false</useIncrementalCompilation>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M3</version>
      </plugin>
    </plugins>
  </build>
</project>

versions:

$ mvn help:system | grep -i jdk
sun.boot.library.path=/opt/jdk-13.0.1/lib
jdk.debug=release
java.home=/opt/jdk-13.0.1
java.runtime.name=OpenJDK Runtime Environment
java.vm.name=OpenJDK 64-Bit Server VM
JDK_HOME=/opt/jdk-13.0.1
JAVA_HOME=/opt/jdk-13.0.1
JAVAC=/opt/jdk-13.0.1/bin/javac

$ mvn -version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T22:00:29+03:00)
Maven home: /usr/share/maven-bin-3.6
Java version: 13.0.1, vendor: Oracle Corporation, runtime: /opt/jdk-13.0.1
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.2-gentoo", arch: "amd64", family: "unix"

It's working fine if I skip test phase with mvn clean package -DskipTests:

BUILD SUCCESS

But when I'm trying to test the project with mvn clean test, I'm getting error (full log with -e is here: https://gist.github.com/g4s8/a08e88143b7b5ceec0e534a34b7ab734):

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project oot: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test failed: Unsupported class file major version 57 -> [Help 1]

It seems surefire plugin can't work with 13 JDK, but plugin docs says "Requirements: Maven 3.x and JDK 1.7 or higher" (JDK 13 is higher than JDK 1.7).

So did I configure something wrong in my pom.xml or surefire plugin is not working with 13 JDK?

Example project to reproduce: https://github.com/g4s8/so58710751

Bermudez answered 5/11, 2019 at 11:48 Comment(8)
The seemed to be an issue on your system cause you are showing a runtime of OpenJDK whereas the output of mvn --version shows Oracle java ...apart from that Maven/Maven Surefire is tested on JDK 8,11,12,13,14 builds.apache.org/view/M-R/view/Maven/job/maven-box/job/…Orectic
It would also be helpful if you add more log output and only the last lines...there are several more lines ...and a pom file is also help full....best would be having a full log output ...furthermore I've doubts that the tests you have running with JUnit Jupiter based on the given junit version 5.X ...so based on that I suppose you have much more dependencies than shown..Orectic
@Orectic thanks, I added more details and uploaded full build log to gists. I think vendor Oracle is OK, since maven points to correct JDK path /opt/jdk-13.0.1 and OpenJDK is Oracle's project, see openjdk.java.netBermudez
What I see that no test is being executed...I have taken the pom of this post and created a gist.github.com/khmarbaise/f896a5dc65d70969081580329d6a6481 . which shows it works fine on JDK 13 ..I have added a single Test case to be executed ....one thing is: Is this pom the whole pom file with all dependencies ?Orectic
@Orectic I created minimal reproducible project for this issue, please see github.com/g4s8/so58710751Bermudez
So this is completely different cause you are using the module system ...First hint never create module named directories keep the usual structure src/main/java/<package> and put the module-info.java into src/main/java Apart from that I'm investigating this...Orectic
Created a pull request to your repository which fixed the issues.Orectic
I've also cleaned up several other things in your project..in particular the location of module-info.java and the structure of your project.Orectic
V
5

Do NOT use any hacks with ASM library. This type of the issue was fixed once for all in the principle using Java API and we do not need to use ASM. This was the fix with Surefire and Failsafe made in the version 3.0.0-M4. It is already available in Maven Central, enjoy!

Verbal answered 17/11, 2019 at 5:6 Comment(0)
O
10

Currently the issue in Maven Surefire plugin is that it's using an older version of org.ow2.asm:asm which causes the issue. I've created an issue on maven-surefire-plugin. The issue can be temporarily circumvented by simply adding a new version of org.ow2.asm:asm to the maven-surefire-plugin:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <dependencies>
      <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm</artifactId>
        <version>7.2</version>
      </dependency>
    </dependencies>
  </plugin>
</plugins>

Update Do not use this fix for version 3.0.0-M4 and above.

Orectic answered 7/11, 2019 at 7:44 Comment(3)
Thanks! It fixes the issueBermudez
There is a VOTE running for maven-surefire-plugin:3.0.0-M4 which fixes the issue....Orectic
Use the version 3.0.0-M4 of Surefire and Failsafe plugin. Do NOT use the ASM dependency below the plugin! It is useles nowadays.Verbal
V
5

Do NOT use any hacks with ASM library. This type of the issue was fixed once for all in the principle using Java API and we do not need to use ASM. This was the fix with Surefire and Failsafe made in the version 3.0.0-M4. It is already available in Maven Central, enjoy!

Verbal answered 17/11, 2019 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.