This error signals that the JVM running Maven has run out of memory. It is caused by maven-compiler-plugin. The best solution to overcome this issue is, edit maven compiler plugin in pom.xml as below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
</configuration>
</plugin>
fork allows running the compiler in a separate process. If false it uses the built in compiler, while if true it will use an executable. Refer below link for more details
https://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError