I\'ve been trying to compile and test a large project to use Gradle. The test run fine until they die unexpectedly. I dug around and resources said that this is due to a mem
I had the same issue but in a CI environment where build are launched in docker container. In that specific case the JVM is not aware of how much memory it can use and you can experience this type of issues.
In order to let the JVM know how much memory is available, you can use
gradle build -Dorg.gradle.jvmargs=-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
and also set it on your test tasks:
test {
jvmArgs "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap"
}
This is a new JVM feature introduced in 8u131+
see: http://royvanrijn.com/blog/2018/05/java-and-docker-memory-limits/