I have been trying to run on mac a ready maven project which works under linux. When calling
mvn clean install
it runs a portion of the tests and then I am getting the following error:
Exception in thread "main" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
I have seen many questions about Perm gen error fixed with adding MAVEN_OPTS
to environmental variables. Right now I have the following environmental variable on my system:
MAVEN_OPTS="-Xmx4096m -XX:MaxPermSize=4096m"
When calling mvn help:system
I can see these options showing up in the configuration.
The project uses Robolectric for testing purposes and (most of the times but not always) prints the following lines before throwing the exception :
[DEBUG] ********************* **GC'ed SdkEnvironment reused!
[ERROR] couldn't load org.robolectric.internal.ParallelUniverse in org.robolectric.bytecode.AsmInstrumentingClassLoader@300abe53
In activity monitor I can see a java process come to life when I start the tests. Its memory usage reaches 1.4~1.5GB before the exception is thrown.
What else should I do to get it working. Thanks for Your help!
EDIT after adding the memory options to sure fire plugin :
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> <configuration> <argLine>-Xmx2048m -XX:MaxPermSize=2048m</argLine> </configuration> </plugin>
and running mvn clean install -e -X
I got the following stack trace:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project android: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was an error in the forked process
[ERROR] java.lang.OutOfMemoryError: PermGen space
[ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
[ERROR] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[ERROR] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[ERROR] at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[ERROR] at org.apache.maven.surefire.report.SmartStackTraceParser.getMinimalThrowableMiniMessage(SmartStackTraceParser.java:166)
[ERROR] at org.apache.maven.surefire.report.SmartStackTraceParser.getString(SmartStackTraceParser.java:151)
[ERROR] at org.apache.maven.surefire.report.PojoStackTraceWriter.smartTrimmedStackTrace(PojoStackTraceWriter.java:61)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:328)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:312)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.toString(ForkingRunListener.java:258)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.testError(ForkingRunListener.java:132)
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:162)
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[ERROR] -> [Help 1]
That's with 2GB of memory for surefire and 4GB for maven.
I fixed this problem by adding another magic environmental variable
JAVA_TOOL_OPTIONS="-Xmx1024m -XX:MaxPermSize=512m -Xms512m"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With