Maven surefire:附加到argLine
我有两个配置文件,可以一起使用,也可以不一起使用来运行一组测试。它们都需要不同的vmarg来运行,但如果它们一起使用,则可以将它们附加到彼此 我要寻找的是一种将argLine设置为当前值加上我设置的值的串联的方法 我希望它能像这样简单Maven surefire:附加到argLine,maven,maven-3,maven-surefire-plugin,Maven,Maven 3,Maven Surefire Plugin,我有两个配置文件,可以一起使用,也可以不一起使用来运行一组测试。它们都需要不同的vmarg来运行,但如果它们一起使用,则可以将它们附加到彼此 我要寻找的是一种将argLine设置为当前值加上我设置的值的串联的方法 我希望它能像这样简单 <argLine>${argLine} -DnewVMArg</argLine> ${argLine}-DnewVMArg 我能做些类似的事情来实现这一点吗 我试图修复它,结果maven陷入了递归循环。它记录在下面 我最近的尝试是全局定
<argLine>${argLine} -DnewVMArg</argLine>
${argLine}-DnewVMArg
我能做些类似的事情来实现这一点吗
我试图修复它,结果maven陷入了递归循环。它记录在下面
我最近的尝试是全局定义一个属性
,然后在概要文件中修改它
在每个配置文件的“属性”块中,我将“覆盖”属性设置为:
<my.argLines>${my.argLines} -myUniqueToProfileArgs</my.argLines>
${my.argLines}-myuniquetoprofiles
在配置文件的每个surefire配置中,我将
设置为:
<argLines>${my.argLines}</argLines>
${my.argLines}
这在逻辑上适合我,但它的求值方式显然不适合网格。正如您所发现的,属性无法引用自身 您需要为每个配置文件定义不同的属性,并最终在surefire调用中连接它们:
<properties>
<!-- it is a good idea not to use empty or blank properties -->
<first.props>-Dprofile1Active=false</first.props>
<second.props>-Dprofile2Active=false</second.props>
</properties>
...
<!-- surefire configuration -->
<argLine>${first.props} ${second.props}</argLine>
...
<profile>
<id>first</id>
<properties>
<first.props>-myUniqueToProfile1Args</first.props>
</properties>
</profile>
<profile>
<id>second</id>
<properties>
<second.props>-myUniqueToProfile2Args</second.props>
</properties>
</profile>
-Dprofile1Active=false
-Dprofile2Active=false
...
)如果您只处理-D系统属性,则可以使用而不是,然后它们将自然组合在一起。其中一个配置文件可能有:
<systemPropertyVariables>
<propertyFromProfile1>value1</propertyFromProfile1>
</systemPropertyVariables>
价值1
第二个配置文件:
<systemPropertyVariables>
<propertyFromProfile2>value2</propertyFromProfile2>
</systemPropertyVariables>
价值2
另外,值得一提的是,这种方法允许您在子POM中重写父POM中的单个属性。在argLine
内部定义默认参数-DnewVMArg
,如下所示:
<properties>
<customArg/>
<argLine>${customArg} -DnewVMArg</argLine>
</properties>
结果
(...)java -jar -DnewVMArg (...)
有个人资料的目标
mvn surefire:test -X -Pprofile1
结果
(...)java -DmyUniqueToProfile1Args -DnewVMArg -jar (...)
Eclipse:Window->Preferences->TestNG->Maven
取消选中“argLine”。当您显式设置参数而不是使用全局变量时,它是否有效?请将整个pom.xml文件放在这里。我认为这不适用于JVM选项,如-Xmx1024m
,只适用于标准-Dfoo=bar
,是吗?这里有一些语言混乱。我刚才说你的说法是正确的。另外,我在回答的开头提到了这个细节:“如果您只处理-D系统属性…”这样,只有profile1或profile2可以积极地对argLine做出贡献,但是在最初的问题中,两个概要文件可以一起使用。
(...)java -jar -DnewVMArg (...)
mvn surefire:test -X -Pprofile1
(...)java -DmyUniqueToProfile1Args -DnewVMArg -jar (...)