Maven surefire:追加到argLine [英] Maven surefire: append to argLine

查看:1129
本文介绍了Maven surefire:追加到argLine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个配置文件,它们可以一起使用或可以不一起运行一组测试.它们每个都需要运行不同的vmargs,但是如果将它们一起使用,可以将它们彼此附加在一起.

I have 2 profiles that may or may not be used together to run a group of tests. They each require different vmargs to run, but if they are used together it's ok to have them appended to each other.

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

What I'm looking for is a way to set argLine to be the concatenation of its current value plus what I set.

我希望它会如此简单

<argLine>${argLine} -DnewVMArg</argLine>

是否有类似的方法可以做到这一点?

Is there something similar I can do to make this happen?

我尝试对其进行修复,这导致maven陷入了递归循环.记录在下面.

I made an attempt at fixing it which results in maven getting stuck in a recursive cycle. It's documented below.

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

My Most recent attempt was to define a property <my.argLines></my.argLines> globally, and then to modify this within the profiles.

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

In each profile, in a properties block, I set overrode the property to:

<my.argLines>${my.argLines} -myUniqueToProfileArgs</my.argLines>

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

In each surefire configuration for the profiles, I set <argLines> to be:

<argLines>${my.argLines}</argLines>

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

This logically fits for me, but the way it evalutes is apparently not going to mesh.

推荐答案

argLine内定义默认参数-DnewVMArg,如下所示:

Define your default arguments -DnewVMArg inside argLine like below:

<properties>
    <customArg/>
    <argLine>${customArg} -DnewVMArg</argLine>
</properties>

定义配置文件参数

<profiles>
    <profile>
        <id>profile1</id>
        <properties>
            <customArg>-DmyUniqueToProfile1Args</customArg>
        </properties>
    </profile>
    <profile>
        <id>profile2</id>
        <properties>
            <customArg>-DmyUniqueToProfile2Args</customArg>
        </properties>
    </profile>
</profiles>

不需要其他插件配置

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <configuration/>
        </plugin>
....

我已经测试了此配置,结果如下.

I have tested this configuration, my results below.

默认

mvn surefire:test -X 

结果

(...)java -jar -DnewVMArg (...) 

具有配置文件的目标

mvn surefire:test -X -Pprofile1

结果

(...)java -DmyUniqueToProfile1Args -DnewVMArg -jar (...) 

这篇关于Maven surefire:追加到argLine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆