![](/img/trans.png)
[英]Maven Surefire test failed: Unsupported class file major version 61
[英]JDK-13 Unsupported class file major version for surefire plugin
我正在嘗試使用 Java-13 和 Maven 創建 Java 模塊項目。 我的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>
版本:
$ 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"
如果我使用mvn clean package -DskipTests
跳過測試階段,它工作正常:
建立成功
但是當我嘗試使用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 文件主要版本 57 -> [幫助 1]
似乎surefire插件無法與13 JDK一起使用,但插件文檔說“要求:Maven 3.x和JDK 1.7或更高版本”(JDK 13高於JDK 1.7)。
那么我是否在我的pom.xml
中配置了錯誤,或者肯定插件不適用於 13 JDK?
要重現的示例項目: https://github.com/g4s8/so58710751
目前 Maven Surefire 插件中的問題是它使用的是舊版本的 org.ow2.asm:asm 導致問題。 我在 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>
更新不要對版本 3.0.0-M4 及更高版本使用此修復程序。
不要對 ASM 庫使用任何 hack。 此類問題在原則上使用 Java API 一次性修復,我們不需要使用 ASM。 這是在3.0.0-M4 版本中對 Surefire 和 Failsafe 進行的修復。 它已經在 Maven Central 中提供,盡情享受吧!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.