Kir*_*ill 5 java maven maven-surefire-plugin java-13
我正在尝试使用 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>
Run Code Online (Sandbox Code Playgroud)
版本:
$ 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"
Run Code Online (Sandbox Code Playgroud)
如果我跳过测试阶段,它工作正常mvn clean package -DskipTests:
建立成功
但是,当我尝试使用 测试项目时mvn clean test,出现错误(完整日志在-e这里:https : //gist.github.com/g4s8/a08e88143b7b5ceec0e534a34b7ab734):
[错误] 无法在项目 oot 上执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test):执行目标 org.apache.maven.plugins 的默认测试:maven-surefire-plugin:3.0.0-M3:test failed: Unsupported class file major version 57 -> [Help 1]
似乎surefire插件不能与13 JDK一起使用,但 插件文档说“要求:Maven 3.x和JDK 1.7或更高”(JDK 13高于JDK 1.7)。
那么我是否在我的pom.xml或surefire插件中配置错误无法与13 JDK一起使用?
要重现的示例项目:https : //github.com/g4s8/so58710751
目前 Maven Surefire 插件中的问题是它使用了旧版本的 org.ow2.asm:asm 导致了这个问题。我在 maven-surefire-plugin 上创建了一个问题。这个问题可以通过简单地向 maven-surefire-plugin 添加一个新版本的 org.ow2.asm:asm 来暂时规避:
<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>
Run Code Online (Sandbox Code Playgroud)
更新 不要将此修复程序用于 3.0.0-M4 及更高版本。
不要对 ASM 库使用任何 hack。这类问题原则上使用Java API就已经解决了,我们不需要使用ASM。这是版本 3.0.0-M4中对 Surefire 和 Failsafe的修复。它已经在 Maven Central 中可用,尽情享受吧!
| 归档时间: |
|
| 查看次数: |
1901 次 |
| 最近记录: |