我正在尝试使用 --enable-preview
将项目迁移到 Java 12。
我在编译器设置中添加了--enable-preview
:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
并且还将它添加到 argLine 中以确保万无一失和故障安全:
<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 配置中,但结果是一样的。
我在这里错过了什么?
这是 surefire/failsafe 中的错误吗?
EDIT2:Surefire 和故障保护配置:
<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>
编辑3: 最小的工作示例在这里:https://github.com/krzyk/lombok-jdk10-example
该项目因 --enable-preview
而失败,但在我删除它时可以正常工作。
最佳答案
这对我有用:
mvn clean install
有效(使用 junit 测试)- IDEA 将模块语言级别正确识别为
12 (Preview) - Switch expressions
- IDEA 工作中的联合测试
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>12</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
环境:
Ubuntu 18.04.3 x64
想法 2019.2.1
maven 3.6.0
jdk:
IMPLEMENTOR="Oracle Corporation" JAVA_VERSION="12" JAVA_VERSION_DATE="2019-03-19"
补充:类似地,这种方法适用于 java 13。
补充:类似地,这种方法适用于 java 17。
关于java - 在 surefire 和 failsafe 中使用启用的预览功能运行测试时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55303837/