简体   繁体   English

JDK-13 不受支持的 class 文件主版本

[英]JDK-13 Unsupported class file major version for surefire plugin

I'm trying to create Java module project with Java-13 and Maven.我正在尝试使用 Java-13 和 Maven 创建 Java 模块项目。 My pom.xml is:我的pom.xml是:

<?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 :如果我使用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 ):但是当我尝试使用mvn clean test测试项目时,我收到了错误(带有-e的完整日志在这里: https://gist.github.com/g4s8/a08e88143b7b5ceeca34b 75 ):

[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] [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 文件主要版本 57 -> [帮助 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).似乎surefire插件无法与13 JDK一起使用,但插件文档说“要求:Maven 3.x和JDK 1.7或更高版本”(JDK 13高于JDK 1.7)。

So did I configure something wrong in my pom.xml or surefire plugin is not working with 13 JDK?那么我是否在我的pom.xml中配置了错误,或者肯定插件不适用于 13 JDK?

Example project to reproduce: https://github.com/g4s8/so58710751要重现的示例项目: https://github.com/g4s8/so58710751

Currently the issue in Maven Surefire plugin is that it's using an older version of org.ow2.asm:asm which causes the issue.目前 Maven Surefire 插件中的问题是它使用的是旧版本的 org.ow2.asm:asm 导致问题。 I've created an issue on maven-surefire-plugin .在 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:只需将新版本的 org.ow2.asm:asm 添加到 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.更新不要对版本 3.0.0-M4 及更高版本使用此修复程序。

Do NOT use any hacks with ASM library.不要对 ASM 库使用任何 hack。 This type of the issue was fixed once for all in the principle using Java API and we do not need to use ASM.此类问题在原则上使用 Java API 一次性修复,我们不需要使用 ASM。 This was the fix with Surefire and Failsafe made in the version 3.0.0-M4 .这是在3.0.0-M4 版本中对 Surefire 和 Failsafe 进行的修复 It is already available in Maven Central , enjoy!它已经在 Maven Central 中提供,尽情享受吧!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven Surefire 测试失败:不支持 class 文件主要版本 61 - Maven Surefire test failed: Unsupported class file major version 61 Maven surefire 插件 2.22.2 构建失败,用于 Junit 5 测试用例,错误不支持 Spring Boot 中的类文件主要版本 56 - Maven surefire plugin 2.22.2 build fails for Junit 5 test cases with errror Unsupported class file major version 56 in spring boot Maven 编译器插件 不支持 class 文件主要版本 60 - Maven compiler plugin Unsupported class file major version 60 Intellij Maven java.lang.IllegalArgumentException: Unsupported class 文件主要版本 61 并且 Entity 使用不支持的 JDK 编译 - Intellij Maven java.lang.IllegalArgumentException: Unsupported class file major version 61 and Entity was compiled with an unsuppported JDK 如何在 Java 13 和 Spring 的 Maven 中修复不受支持的类文件主要版本 57 - How to fix Unsupported class file major version 57 in maven for Java 13 and Spring Spark 错误 - 不支持的类文件主要版本 - Spark Error - Unsupported class file major version 不支持 class 文件主要版本 61 - Unsupported class file major version 61 TomEE 8 不支持的类文件主要版本 61 - Unsupported class file major version 61 with TomEE 8 IllegalArgumentException:'不支持 class 文件主要版本 55' - IllegalArgumentException: 'Unsupported class file major version 55' 不支持 class 文件主要版本 58 - Unsupported class file major version 58
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM