在具有surefire和failsafe的预览功能的情况下运行测试时出现问题 [英] Problem running tests with enabled preview features in surefire and failsafe
问题描述
我正在尝试使用--enable-preview
将项目迁移到Java 12.
I'm trying to migrate a project to Java 12, with --enable-preview
.
我在编译器设置中添加了--enable-preview
:
I added --enable-preview
in compiler settings:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
并且还将其添加到argLine中以确保安全和失效保护:
And also added it in argLine for surefire and failsafe:
<properties>
<argLine>--enable-preview</argLine>
</properties>
并执行mvn clean verify
结果:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project lombok-jdk10: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test failed: java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/kirela/lombok/BarTest (class file version 56.65535). Try running with '--enable-preview' -> [Help 1]
我还尝试将argLine直接添加到surefire/failsafe配置中,但是结果是相同的.
I also tried adding argLine directly to surefire/failsafe configuration, but the result is same.
我在这里想念什么?
这是surefire/failsafe中的错误吗?
I this a bug in surefire/failsafe?
Surefire和故障安全配置:
Surefire and failsafe config:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<forkCount>2</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<forkCount>2</forkCount>
</configuration>
</plugin>
最小的工作示例在这里: https://github.com/krzyk/lombok-jdk10-example
Minimal working example is here: https://github.com/krzyk/lombok-jdk10-example
该项目失败并显示--enable-preview
,但是当我删除它时可以正常工作.
The project fails with --enable-preview
, but works when I remove it.
推荐答案
有两种解决方案:
将--enable-preview
添加到MAVEN_OPTS
环境变量.
Add --enable-preview
to MAVEN_OPTS
environment variable.