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

那年仲夏 提交于 2020-01-10 19:37:07

问题


I am using maven-surefire-plugin + Sonar together and I would like to add some extra value to argLine parameter of the maven-surefire-plugin.

So I did it:

<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>

But in this case I am overwriting the original value of the argLine parameter and Sonar does not generate jacoco.exec file.

I can see in the maven debug log (-X) that the value of argLine param without overwriting its value is -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.

What is the proper way to APPEND the original value of this parameter (keep the original + add extra values)?

I am using Apache Maven 3.5.0, Java version: 1.8.0_131, vendor: Oracle Corporation.


回答1:


The official documentation calls that late replacement.

If you do the following you will overwrite the value of the argLine parameter which is set by another plugins before, so DO NOT DO THIS:

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

The proper way to keep the existing values and add your configuration is to use @{...} syntax:

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

OR you can set argLine as a property in your pom.xml file:

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

Both solutions above works properly.



来源:https://stackoverflow.com/questions/46489455/append-the-value-of-argline-param-in-maven-surefire-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!