1
votes

I have a project with the following ./mvn/jvm.config :

-Xms32g -Xmx64g -XX:MaxDirectMemorySize=20g

I was wondering if I configure my maven surfire plugin as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.9</version>
    <configuration>
        <argLine>-Xms12g -Xmx30g -XX:MaxDirectMemorySize=30g</argLine>
        <suiteXmlFiles>
            <suiteXmlFile>src/test/resources/RunMmoTests.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin> 

I know that my jvm.config will set the MAVEN_OPTS environment variable, but I can't find any documentation stating the precedence between MAVEN_OPTS and surfire argLine. Which one override the other? After running some tests, I have the feeling that the surfire argLine override whatever argument defined in MAVEN_OPTS. Is my guess correct??

Many thanks

1
First why are you using such an old version of maven-surefire-plugin ? Really need memory settings like this for unit tests? Furthermore maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html. And running a build with 64GiB ? how many millions of modules do you use? What maven version/jdk etc. are you running?khmarbaise
I am working on the development of an in memory database and we run a bunch of test on/off heap that includes millions of input data that's why I need to run my tests using different memory set up. I am using: - Jdk 11 - maven 3.6.1Mr. D
So this are integration tests which should be running via maven-failsafe-plugin also most recent should be used... so why using such old version of surefire? Cause 2.9 is about 9 years old ? I strongly recommend to use most recent versions ...khmarbaise
So why do you add memory settings to your command for maven which I have my doubts needs 64 G to build your project. In your tests you could do that but you should fork to use such things...khmarbaise
These are rather scaling than integration tests ^^. Regarding the surefire question, I can't really answer this I am not in the one maintaining these tests but I will recommend that the owner update to newer versions. The 64G is not for maven to build the project, they are jvm options. Sorry if I mislead you I didn't provide the whole plugin config. Please check my updatedMr. D

1 Answers

1
votes

If argLine does not define JVM options, will surefire forked jvm inherit the jvm options defined in .mvn/jvm.config?

It will not. You may have completely different requirements for building the project than for running the tests.

Here the comment in the source code of maven-surefire:

For the default, the JVM will be a new instance of the same VM as the one used to run Maven. JVM settings are not inherited from MAVEN_OPTS.

When we invoke the mvn command (mvn.cmd or bin/mvn) Maven reads and sets different environment variables and does it differently in Linux and Windows.

  • On Linux, the mvn command sets the MAVEN_OPTS variable by concatenating the existing MAVEN_OPTS with the $MAVEN_PROJECTBASEDIR/.mvn/jvm.config file and then invokes java passing the MAVEN_OPTS as a parameter.
  • On Windows, the mvn command sets JVM_CONFIG_MAVEN_PROPS with the content of jvm.config and then invokes java passing MAVEN_OPTS and JVM_CONFIG_MAVEN_PROPS

The surefire plugin forks a separate process for executing test by invoking java command but it will not pass the MAVEN_OPTS or JVM_CONFIG_MAVEN_PROPS as parameters to JVM.

If you want to set the same JVM parameters for running test as for running maven then you can use ${parameters} in argLines. For example like this:

<configuration>
  <argLine>${MAVEN_OPTS}</argLine>
</configuration>