Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 735
zappee Avatar asked Sep 29 '17 13:09

zappee


People also ask

How do I pass system properties in Maven?

To provide System Properties to the tests from command line, you just need to configure maven surefire plugin and use -D{systemproperty}={propertyvalue} parameter in commandline. Run Single Test with Maven : $ mvn test -Dtest=MessageUtilTest#msg_add_test -Dmy_message="Hello, Developer!"

How do I run maven surefire plugin?

The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.

What is Forkmode in Maven?

The parameter forkCount defines the maximum number of JVM processes that maven-surefire-plugin will spawn concurrently to execute the tests. It supports the same syntax as -T in maven-core: if you terminate the value with a 'C', that value will be multiplied with the number of available CPU cores in your system.


1 Answers

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.

like image 181
zappee Avatar answered Sep 30 '22 18:09

zappee