我正在尝试将一个项目迁移到Java 12,并使用 --enable-preview
。
我在编译器设置中添加了 --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>
同时也在surefire和failsafe的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的一个bug吗?
编辑2:Surefire和failsafe配置:
<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
时失败,但在我删除它后可以运行。
maven.compiler.source
和maven.compiler.target
属性的值是什么? - Izbassar Tolegen