Running a large Gradle build (with JDK7) I receive two OutOfMemoryErrors
:
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Test worker"
When I set the two environment variables below, the build runs through and works just fine:
export JAVA_OPTS="-Xmx2048m -XX:MaxPermSize=1024m"
export JAVA_TOOL_OPTIONS="-Xmx1024m -XX:MaxPermSize=1024m -Xms768m"
./gradlew test --stacktrace
...
Picked up JAVA_TOOL_OPTIONS: -Xmx1024m -XX:MaxPermSize=1024m -Xms768m
...
Is there a way to include those settings in gradle.properties
or in build.gradle
? If yes, what is the correct usage?
I already tried this in build.gradle
:
allprojects {
System.setProperty('JAVA_OPTS', "-Xmx2048m -XX:MaxPermSize=1024m")
System.setProperty('JAVA_TOOL_OPTIONS', "-Xmx1024m -XX:MaxPermSize=1024m -Xms768m")
}
but that doesn't work.
Could you please try to create a gradle.properties
file which should be located next to root build.gradle
and will it with the following content:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m
Another option is to set the required options via compileJava
task, please see here and here.
Unfortunately no idea how JAVA_TOOL_OPTIONS
can be set, it seems unsupported.
From what I gather the gradlew is intended to be tweaked. So adding those environment variables in the gradlew script would be acceptable and the setting would be available in all CI environments.
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