in Code

[SOLVED] Gradle: How to increase the Java Compiler’s available Heap Memory

The documentation is not very clear on what all the available options are…
after much Googling and many different attempts finally figured out how to raise the maximum heap of the compiler from within the script.

[pastacode lang=”java” manual=”apply%20plugin%3A%20%E2%80%98java%E2%80%99%0A%0AcompileJava%20%7B%0A%2F%2Fraise%20heap%0Aoptions.fork%20%3D%20%E2%80%98true%E2%80%99%0Aoptions.forkOptions.with%20%7B%0AmemoryMaximumSize%20%3D%20%E2%80%9C2048m%E2%80%9D%0A%7D%0A%7D” message=”” highlight=”” provider=”manual”/]

So I’ve noticed this works great on MacOSX, but it doesn’t work at all on Windows 8.

The solution to increasing the JVM’s Heap has been to remove those options from script and add a new file on the same folder as where your file lives called ‘’

These are the contents that made it work for both Mac and Windows (I’ve still not tested this on my linux box)

[pastacode lang=”java” manual=”org.gradle.jvmargs%3D-Xms256m%20-Xmx1024m” message=”” highlight=”” provider=”manual”/]

Write a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Hi,

    I got issues related to uploadArchives which sometimes shows the error PermGen space something (when run on bamboo build server, it always builds locally) which made me think of memory related problems. Then I find your post. I added org.gradle.jvmargs=-Xms256m -Xmx1024m to a placed next to the project’s build.gradle and after that the build was successful. However, the following 3 builds (no code changes) weren’t so I’m confused.

    Do you know what the default values for Xms and Xmx are?


  2. Thank you! I recently upgraded versions and was getting heap space errors even though I had settings to bump memory up. Removed those and added the properties file and I can at least get the eclipse target to run. However, no success with test target… still investigating.

  3. In order to increase the memory for may tasks, I had to add the following:

    tasks.withType(GroovyCompile) {
    configure(groovyOptions.forkOptions) {
    memoryMaximumSize = ‘1g’
    jvmArgs = [‘-XX:MaxPermSize=512m’, ‘-Xms512m’, ‘-Xmx1g’]

  4. Thanks, I had to change a bit in Linux, only the value format.

    compileJava {
    //raise heap
    options.fork = true
    options.forkOptions.with {
    memoryMaximumSize = ‘2048m’