英文:
maven surefire plugin not using --enable-preview mode
问题
这是我的pom.xml文件:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>13</source>
<target>13</target>
<release>13</release>
<compilerArgs>
--enable-preview
</compilerArgs>
</configuration>
</plugin>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<reuseForks>false</reuseForks>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
问题在于构建过程没有问题,但是在运行测试时出现以下错误:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test
(default-test) on project foo-project: Execution default-test of goal
org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test failed:
java.lang.UnsupportedClassVersionError: Preview features are not
enabled for it/project/MyTest (class file version 57.65535). Try
running with '--enable-preview' -> [Help 1]
我应该在pom.xml中插入什么内容,以便在启用预览模式的情况下执行测试呢?
谢谢。
英文:
Here it's my pom.xml:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>13</source>
<target>13</target>
<release>13</release>
<compilerArgs>
--enable-preview
</compilerArgs>
</configuration>
</plugin>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<reuseForks>false</reuseForks>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
The problem is that the build goes ok, but when tests are launched I get:
> [ERROR] Failed to execute goal
> org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test
> (default-test) on project foo-project: Execution default-test of goal
> org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test failed:
> java.lang.UnsupportedClassVersionError: Preview features are not
> enabled for it/project/MyTest (class file version 57.65535). Try
> running with '--enable-preview' -> [Help 1]
What I have to insert in pom.xml for executing tests with enabled preview mode?
Thanks.
答案1
得分: 1
我遇到了类似的问题。
- Maven版本:3.8.1
- Surefire版本:2.22.2
- JK:13
我使用了<reuseForks>true</reuseForks>
,它正常工作了。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<release>${java.version}</release>
<showWarnings>true</showWarnings>
<compilerArgs>
<compilerArg>-Xlint:unchecked,deprecation</compilerArg>
<compilerArg>--enable-preview</compilerArg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<reuseForks>true</reuseForks>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
英文:
I had a similar problem.
- Maven Version: 3.8.1
- Surefire Version: 2.22.2
- JK: 13
I used <reuseForks>true</reuseForks>
and it worked fine.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<release>${java.version}</release>
<showWarnings>true</showWarnings>
<compilerArgs>
<compilerArg>-Xlint:unchecked,deprecation</compilerArg>
<compilerArg>--enable-preview</compilerArg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<reuseForks>true</reuseForks>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论