Maven surefire:附加到argLine

use*_*605 14 maven-3 maven maven-surefire-plugin

我有2个配置文件可能会或可能不会一起用于运行一组测试.它们每个都需要不同的vmarg来运行,但如果它们一起使用,可以将它们相互附加.

我正在寻找的是一种将argLine设置为其当前值加上我设置的串联的方法.

我希望它会如此简单

<argLine>${argLine} -DnewVMArg</argLine>
Run Code Online (Sandbox Code Playgroud)

我能做些类似的事情来实现这一目标吗?

我试图修复它,导致maven陷入递归循环.它记录在下面.

我最近的尝试是<my.argLines></my.argLines>全局定义属性,然后在配置文件中修改它.

在每个配置文件中,在属性块中,我将属性覆盖为:

<my.argLines>${my.argLines} -myUniqueToProfileArgs</my.argLines>
Run Code Online (Sandbox Code Playgroud)

在配置文件的每个surefire配置中,我设置<argLines>为:

<argLines>${my.argLines}</argLines>
Run Code Online (Sandbox Code Playgroud)

这在逻辑上适合我,但它评估的方式显然不会啮合.

Mar*_*szS 7

-DnewVMArgargLine下面定义您的默认参数:

<properties>
    <customArg/>
    <argLine>${customArg} -DnewVMArg</argLine>
</properties>
Run Code Online (Sandbox Code Playgroud)

定义配置文件参数

<profiles>
    <profile>
        <id>profile1</id>
        <properties>
            <customArg>-DmyUniqueToProfile1Args</customArg>
        </properties>
    </profile>
    <profile>
        <id>profile2</id>
        <properties>
            <customArg>-DmyUniqueToProfile2Args</customArg>
        </properties>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

不需要额外的插件配置

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <configuration/>
        </plugin>
....
Run Code Online (Sandbox Code Playgroud)

我已经测试了这个配置,我的结果如下.

默认

mvn surefire:test -X 
Run Code Online (Sandbox Code Playgroud)

结果

(...)java -jar -DnewVMArg (...) 
Run Code Online (Sandbox Code Playgroud)

目标与配置文件

mvn surefire:test -X -Pprofile1
Run Code Online (Sandbox Code Playgroud)

结果

(...)java -DmyUniqueToProfile1Args -DnewVMArg -jar (...) 
Run Code Online (Sandbox Code Playgroud)


bla*_*ild 0

正如您所发现的,属性不能引用自身。

\n\n

您需要为每个配置文件定义不同的属性,并最终在您的 Surefire 调用中将它们连接起来:

\n\n
<properties>\n  <!-- it is a good idea not to use empty or blank properties -->\n  <first.props>-Dprofile1Active=false</first.props>\n  <second.props>-Dprofile2Active=false</second.props>\n</properties>\n...\n    <!-- surefire configuration -->\n    <argLine>${first.props} ${second.props}</argLine>    \n...\n<profile>\n  <id>first</id>\n  <properties>\n    <first.props>-myUniqueToProfile1Args</first.props>\n  </properties>\n</profile>\n<profile>\n  <id>second</id>\n  <properties>\n    <second.props>-myUniqueToProfile2Args</second.props>\n  </properties>\n</profile>\n
Run Code Online (Sandbox Code Playgroud)\n\n

另请注意非空默认值。Maven 有一些令人惊讶的方式来处理这些问题。为了安全起见,请使用无害的非空白默认值(请参阅Maven 中的 \xe2\x80\x9cNull\xe2\x80\x9d 与 \xe2\x80\x9cempty\xe2\x80\x9d 参数

\n