Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven surefire: append to argLine

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.

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

I was hoping it would as simple as

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

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

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

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>

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.

like image 305
user321605 Avatar asked Dec 11 '12 22:12

user321605


People also ask

What is argLine in surefire?

Since the Version 2.17 using an alternate syntax for argLine , @{... } allows late replacement of properties when the plugin is executed, so properties that have been modified by other plugins will be picked up correctly.

What is perCoreThreadCount?

Note that the perCoreThreadCount is a "multiplier" of a sorts. With this parameter set to true (the default value), you will get the specified number of threads per CPU core. Also note that in this specific case threadCountSuites=2 has the same effect as threadCount=2 , since we are using parallel=suites .


2 Answers

Define your default arguments -DnewVMArg inside argLine like below:

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

Define profiles arguments

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

Additional plugin configuration is not required

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

I have tested this configuration, my results below.

Default

mvn surefire:test -X 

Result

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

Goal with profile

mvn surefire:test -X -Pprofile1

Result

(...)java -DmyUniqueToProfile1Args -DnewVMArg -jar (...) 
like image 113
MariuszS Avatar answered Sep 19 '22 13:09

MariuszS


If you are dealing only with -D system properties, you could use <systemPropertyVariables> instead of <argLine> and then they will be combined naturally. One of the profiles could have:

<systemPropertyVariables>
    <propertyFromProfile1>value1</propertyFromProfile1>
</systemPropertyVariables>

and the second profile:

<systemPropertyVariables>
    <propertyFromProfile2>value2</propertyFromProfile2>
</systemPropertyVariables>

Also, it's worth mentioning that this approach allows you to override in child poms individual properties from parent poms.

like image 23
Bogdan Calmac Avatar answered Sep 21 '22 13:09

Bogdan Calmac