Upgrading from 4.10 to 5.0 - Java Heap/GC Errors when executing tests

I am trying to upgrade a project that mainly executes ‘test’ tasks from 4.8 to 5.4.1.

I’ve been following the recommendations at https://docs.gradle.org/5.4/userguide/upgrading_version_4.html and have upgraded to 4.10 with no issues.

Once I went to 5.0, I started running into ‘Java Heap’ and ‘GC overhead limit exceeded’ issues. This always happens on the ‘compileTestGroovy’ task. Our test suite uses Groovy, Spock and JUnit.

I’ve seen a couple of posts that led me to do the following. These being:

Based on these posts I’ve:
Added the following to the gradle.properties file:

  • org.gradle.daemon=false

  • org.gradle.jvmargs=-Xms512m -Xmx2048m -Xss1M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

  • Note: I’ve tried a couple of different limits here especially with Xmx.

Added the following to my build.gradle file:
test {
minHeapSize = “1024m”
maxHeapSize = “2048m”
forkEvery 100
jvmArgs ‘-Xmx2048m’, ‘-Xms1024m’
}

  • Notes:
    ** I’ve also tried different combinations here.
    ** We’ve let all these default previously.

After I completely kill everything, I can run a task (locally) that executes tests once (with errors, but that will be a separate ticket). After that, if I execute the same task again it executes much longer (first run is a little over three minutes, subsequent runs take over 18 minutes) and I get the ‘Java Heap Space’ error.

What else could I be missing?

Just posting an update.

Adding the following to my build.gradle file seems to have solved this issue:

tasks.withType(GroovyCompile) {
configure(groovyOptions.forkOptions) {
jvmArgs = [’-Xms512m’, ‘-Xmx2048m’]
}
}