I am currently switching from ant to gradle for my multi module web application and at the moment it seems that the current version of Gradle (M9) might be running up agains
GRADLE_OPTS value in gradlew was set like this for me before
DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
This was causing compileJava fail like below in Jenkin
What went wrong: Execution failed for task ':compileJava'. GC overhead limit exceeded
Later I had changed DEFAULT_JVM_OPTS like below to make Jekin build success -
DEFAULT_JVM_OPTS="-Xmx512m" "-Xms64m"
If using the Gradle Wrapper you can set DEFAULT_JVM_OPTS
in gradlew
like this:
DEFAULT_JVM_OPTS="-Xmx512m"
Set it in a similar fashion in gradlew.bat
if you're on Windows:
set DEFAULT_JVM_OPTS=-Xmx512m
The Gradle Wrapper task can also be modified to include this automatically. This is how the Gradle developers have solved it:
wrapper {
gradleVersion = '1.8'
def jvmOpts = "-Xmx512m"
inputs.property("jvmOpts", jvmOpts)
doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
scriptFile.write scriptFile.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
batchScript.write batchScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}
I am using following version of gradle.properties to make Gradle performance better in Android projects
# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true
I personally went through all the articles here but doing these steps fixed it.
If you are using 32 bit jvm that may be the issue install a 64 bit jvm.
In run time parameters add:
-Xmx 2048m
I just found a very nice way to handle this problem. No need for custom gradle wrapper or GRADLE_OPTIONS.
compileJava {
options.fork = true // Fork your compilation into a child process
options.forkOptions.setMemoryMaximumSize("4g") // Set maximum memory to 4g
}
Run Gradle with the --info option to see where it's going to use your parameter for max memory size.
gradle build --info
You need to give more memory to the Gradle JVM, not to the compile task/JVM. One way to do so is via the GRADLE_OPTS
environment variable (GRADLE_OPTS=-Xmx512m
).