You can set Java parameters for Maven at different points and levels (globally or through plugin configuration):
Plugin configuration: for compilation only
Using the Maven Compiler Plugin configuration to compile application code and test code, you can set the necessary Xmx, Xms, Xss parameters using the compileArgs configuration record, available for compile and testCompile purposes. An official example is available here on other SO answers like this one . <w> An example is also shown below at the third point.
Plugin configuration: only to run tests
Using the Maven Surefire Plugin configuration to run tests, you can set the necessary Java parameters that will be used at run time through the argLine test configuration argLine . An official example is available here .
An example is also shown below at the third point.
Plugin configuration: via Properties (and profiles)
You can combine the two parameters above (in the case of general Java options) as a property value to go to the compileArgs and argLine configuration argLine or have different properties for each configuration (according to your needs).
<property> <jvm.options>-Xmx256M</jvm.options> </property> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <compilerArgs> <arg>${jvm.options}</arg> </compilerArgs> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <argLine>${jvm.options}</argLine> </configuration> </plugin> </plugins> [...] </build> [...]
Using properties gives you two additional benefits (besides centralization): you can use profiles to personalize it based on different desired behaviors (and an example in this SO answer ), and you can also override them through the command line, for example:
mvn clean install -Djvm.options=-Xmx512
Global / project configuration: parameter file
Starting with Maven 3.3.1, you can specify your parameters in the .mvn/jvm.config for each project. This is an alternative to MAVEN_OPTS and a more narrowed area (by design). However, since this is a new feature of Maven, people should be aware of this, otherwise troubleshooting and maintenance may be affected.
Global / Env configuration: MAVEN_OPTS
Maven is a well-known environment variable for setting global execution parameters; however, it is applied to all Maven assemblies using this environment (that is, for each registered user).
When you start Maven using the -X option (debugging is enabled) you will have the following result as part of your assembly:
[DEBUG] properties used {java.vendor=Oracle Corporation, ... , env.MAVEN_OPTS=-Xmx256M, ...
Update
In the end, the mvn command executed is an OS script. MAVEN_BATCH_ECHO looked at it on Windows, I found an opportunity to use the MAVEN_BATCH_ECHO parameter, which, if it is turned on (the value set to on ), will be an echo of any command executed by the script, and as such also a java call, where you can see Are your parameters ( MAVEN_OPTS ) correctly selected along with a complete list of parameters passed to it.
Here is the test I tested on Windows:
set MAVEN_BATCH_ECHO=on set MAVEN_OPTS=-Xmx256M mvn compile > output.txt
NOTE. output.txt will contain quite a lot of text, providing assembly output and additional echo execution. As part of this, he provided:
>"path_to_\jdk1.7\bin\java.exe" -Xmx256M -classpath "path_to\apache-maven-3.1.1\bin\..\boot\plexus-classworlds-2.5.1.jar" "-Dclassworlds.conf=path_to\apache-maven-3.1.1\bin\..\bin\m2.conf" "-Dmaven.home=path_to\apache-maven-3.1.1\bin\.." org.codehaus.plexus.classworlds.launcher.Launcher compile
As you can see, the option -Xmx256M was correctly selected. If the maven script for another OS does not provide this option, you can simply add it to the script (just executing echo before executing java , showing this command will also suffice).
You can find the maven script in the maven installation folder in the bin subfolder.
Update2
In addition, since Maven is a Java tool, and as you can see from its script, it calls the java command, you can see all of the available options as suggested in this SO answer , by slightly modifying the Maven script and using the jinfo command, which should really give you an answer according to this other SO answer .