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
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