【问题标题】:maven surefire plugin not using --enable-preview modemaven surefire 插件不使用 --enable-preview 模式
【发布时间】:2023-03-28 05:11:01
【问题描述】:

这是我的 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] 未能执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project foo-project: 执行目标的默认测试 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test failed: java.lang.UnsupportedClassVersionError:预览功能不 为 it/project/MyTest 启用(类文件版本 57.65535)。尝试 运行 '--enable-preview' -> [帮助 1]

我必须在 pom.xml 中插入什么来执行启用预览模式的测试?

谢谢。

【问题讨论】:

标签: java maven maven-surefire-plugin java-13


【解决方案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>

【讨论】:

    猜你喜欢
    • 2020-01-21
    • 2011-03-12
    • 2018-12-20
    • 1970-01-01
    • 2014-01-07
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    相关资源
    最近更新 更多