Gradle: increase heap size for java process started by gradle run task

Use this command in Linux: export _JAVA_OPTIONS="-Xms4000m -Xmx8000m" where values 4000 and 8000 can be changed. Instead of JAVA_OPTS use _JAVA_OPTIONS


Old answer: You can set or increase memory usage limits (or other JVM arguments) used for Gradle builds and the Gradle Daemon by editing $GRADLE_USER_HOME/.gradle/gradle.properties (~/.gradle/gradle.properties by default), and setting org.gradle.jvmargs:

org.gradle.jvmargs=-Xmx2024m -XX:MaxPermSize=512m

Source: https://riptutorial.com/gradle/example/11911/tuning-jvm-memory-usage-parameters-for-gradle


As @Opal states above it is not possible.

The easiest/simplest alternative I could find (for now) is to add this little snippet to the build.gradle file:

tasks.withType(JavaExec) {
    jvmArgs = ['-Xms512m', '-Xmx512m']
}

Alternatively, the environment variable _JAVA_OPTIONS the can be used. Even better: the environment variable JAVA_TOOL_OPTIONS; the content of this variable will be used as (additional) JVM options.

Thanks @ady for the hints.

Tags:

Java

Heap

Gradle