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

Kirill
  • 7,580
  • 6
  • 44
  • 95
  • 2
    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 https://builds.apache.org/view/M-R/view/Maven/job/maven-box/job/maven-surefire/job/master/ – khmarbaise Nov 05 '19 at 12:02
  • 1
    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.. – khmarbaise Nov 05 '19 at 12:14
  • @khmarbaise 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 https://openjdk.java.net/ – Kirill Nov 05 '19 at 12:28
  • 1
    What I see that no test is being executed...I have taken the pom of this post and created a https://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 ? – khmarbaise Nov 05 '19 at 14:34
  • @khmarbaise I created minimal reproducible project for this issue, please see https://github.com/g4s8/so58710751 – Kirill Nov 05 '19 at 18:55
  • 1
    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/` and put the `module-info.java` into `src/main/java` Apart from that I'm investigating this... – khmarbaise Nov 06 '19 at 17:49
  • 1
    Created a pull request to your repository which fixed the issues. – khmarbaise Nov 06 '19 at 18:01
  • 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. – khmarbaise Nov 07 '19 at 07:45

2 Answers2

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.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
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!

tibor17
  • 1,043
  • 6
  • 9