Maven Surefire插件没有使用–enable-preview模式。

huangapple go评论73阅读模式
英文:

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:

...
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.8.1&lt;/version&gt;
            &lt;configuration&gt;
                &lt;source&gt;13&lt;/source&gt;
                &lt;target&gt;13&lt;/target&gt;
                &lt;release&gt;13&lt;/release&gt;
                &lt;compilerArgs&gt;
                    --enable-preview
                &lt;/compilerArgs&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
...
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.22.2&lt;/version&gt;
            &lt;configuration&gt;
                &lt;reuseForks&gt;false&lt;/reuseForks&gt;
                &lt;argLine&gt;--enable-preview&lt;/argLine&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;

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

我使用了&lt;reuseForks&gt;true&lt;/reuseForks&gt;,它正常工作了。

<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 &lt;reuseForks&gt;true&lt;/reuseForks&gt; and it worked fine.

       &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;version&gt;${maven.compiler.plugin.version}&lt;/version&gt;
            &lt;configuration&gt;
                &lt;release&gt;${java.version}&lt;/release&gt;
                &lt;showWarnings&gt;true&lt;/showWarnings&gt;
                &lt;compilerArgs&gt;
                    &lt;compilerArg&gt;-Xlint:unchecked,deprecation&lt;/compilerArg&gt;
                    &lt;compilerArg&gt;--enable-preview&lt;/compilerArg&gt;
                &lt;/compilerArgs&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
            &lt;version&gt;${surefire.plugin.version}&lt;/version&gt;
            &lt;configuration&gt;
                &lt;includes&gt;
                    &lt;include&gt;**/*Test.java&lt;/include&gt;
                &lt;/includes&gt;
                &lt;reuseForks&gt;true&lt;/reuseForks&gt;
                &lt;argLine&gt;--enable-preview&lt;/argLine&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年4月5日 22:21:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/61044079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定