[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 gradle.build script.

apply plugin: ‘java’

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

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 gradle.build script and add a new file on the same folder as where your gradle.build file lives called ‘gradle.properties’

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

org.gradle.jvmargs=-Xms256m -Xmx1024m


  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 gradle.properties 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’

Submit a comment