Well, this error signals that the JVM running Maven has run out of memory. This could have various causes, e.g.
- You are building a very big multi-module project, each module requires a certain amount of memory so with increasing number of modules the amount of required memory increases as well until the JVM finally runs out of "Java heap space".
- You are using some plugins that perform memory-intensive operations like analyzing the class files of all project dependencies.
- You are using the Maven Compiler Plugin with the option fork=false (default) and your project has a lot of source files to compile. When using the Java compiler in embedded mode, each compiled class will consume heap memory and depending on the JDK being used this memory is not subject to gargabe collection, i.e. the memory allocated for the compiled classes will not be freed. The resultant error message typically says "PermGen space".
Fixing this error is usually just a matter of assigning more memory to the JVM. If you run from the command line, this can be done by means of the environment variable
MAVEN_OPTS. This variable can be used to specify options for the JVM itself. In case of "Java heap space", the option of interest is
-Xmx, in case of "PermGen space" it's usually
-XX:MaxPermSize. For example, on Windows you would use
set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=128m
or on a Unix-like system
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"
For the special case of the Maven Compiler Plugin, you also have the option to configure the plugin to use
The Unix command lacks quotes, it should be: