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

zappee :

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.

zappee :

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=459058&siteId=1