Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying Maven memory parameter without setting MAVEN_OPTS environment variable

I was wondering if it is possible to specify Maven memory boundaries with a syntax similar to:

mvn -Dtest=FooTest -DXmx=512M clean test 

I tried a couple of variations till now, unsuccessfully.
I am aware of MAVEN_OPTS environment variable, but I would like to avoid that.

Related to the above question, it would be nice to know if there is the possibility to specify the memory behavior of the surefire plugin in a similar manner, so that it forks the jvm using the overridden memory amount (eventually overriding the <argLine> parameter in the pom plugin configuration, if present)

like image 799
Ghiro Avatar asked Sep 23 '11 10:09

Ghiro


People also ask

Which environment variable will you modify to increase the memory used by Maven?

You can start Maven with extra memory using MAVEN_OPTS environment variable.

What is MAVEN_OPTS environment variable?

MAVEN_OPTS environment variable: This variable contains parameters used to start up the JVM running Maven and can be used to supply additional options to it. E.g. JVM memory settings could be defined with the value -Xms256m -Xmx512m .

How much memory does Maven use?

Once you have Maven installed in your system, the very next step is to fine-tune it for an optimal performance. By default, the maximum heap allocation is 512 MB, which starts from 256 MB ( -Xms256m to -Xmx512m ).


2 Answers

To specify the max memory (not via MAVEN_OPTS as originally requested) you can do the following:

mvn clean install -DargLine="-Xmx1524m" 
like image 140
Chris Ritchie Avatar answered Sep 27 '22 22:09

Chris Ritchie


You can configure the surefire-plugin to use more memory. Take a look on Strange Maven out of memory error.

Update: If you would like to set the parameter from command-line take a look on {{mvn.bat}} (or {{mvn}} shell script) in your maven installation directory. It uses with additional options specified in command line.

Next possibility is to set surefire-plugin and use properties specified in command-line, e.g. mvn ... -Dram=512

and

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-surefire-plugin</artifactId>     <version>2.5</version>     <configuration>         <forkMode>once</forkMode>         <argLine>-Xms${ram}m -Xmx${ram}m</argLine>     </configuration> </plugin> 
like image 31
amra Avatar answered Sep 27 '22 22:09

amra