在 maven-surefire-plugin 中附加 argLine 参数的值

Append the value of argLine param in maven-surefire-plugin

我正在同时使用 maven-surefire-plugin + Sonar,我想为 maven-surefire-plugin 的 argLine 参数添加一些额外的值。

所以我做到了:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20.1</version>
            <configuration>
                <argLine>-DCRR.Webservice.isSimulated=true -D...</argLine>
            </configuration>
        </plugin>
        ...
    </plugins>
</build>

但在这种情况下,我覆盖了 argLine 参数的原始值,Sonar 不会生成 jacoco.exec 文件。

我可以在 maven 调试日志 (-X) 中看到 argLine 参数的值没有覆盖它的值是 -javaagent:/opt/jenkins/.../myproject-SONAR/.repository/org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128-runtime.jar=destfile=/opt/jenkins/.../myproject-SONAR/target/jacoco.exec.

附加此参数原始值的正确方法是什么(保留原始值+添加额外值)?

我正在使用 Apache Maven 3.5.0,Java 版本:1.8。0_131,供应商:Oracle Corporation。

官方文档称late replacement

如果您执行以下操作,您将覆盖之前由其他插件设置的 argLine 参数的值,因此 请勿这样做:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-D... -D...</argLine>
    </configuration>
</plugin>

保留现有值并添加配置的正确方法是使用 @{...} 语法:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>@{argLine} -D... -D...</argLine>
    </configuration>
</plugin>

或者您可以在 pom.xml 文件中将 argLine 设置为 property

<properties>
    <argLine>-DCRR.Webservice.isSimulated=true -D...</argLine>
</properties>

以上两种解决方案都可以正常工作。

谢谢!

在我的例子中是:

<argLine>${tycho.testArgLine} -D...</argLine>