Docker Process 'Gradle Test Executor 8' finished with non-zero exit value 137

If our Build Jobs run inside a Docker container then we receive continue the error:

Process ‘Gradle Test Executor 8’ finished with non-zero exit value 137

It sound like that Gradle consume to many memory through pooling of JVM’s. The docker container is limit to 4 GB. The Gradle options limits the Java memory to 1 GB. This should be enough.

Are there any recommendation to handle this?

I also had this problem and found a workaround by setting

test {
	maxHeapSize = "128m"
}

Cheers, Tobias.

Where do I set this option? Which file? I set it in my build.gradle file and the build fails. I use v4.71

I figured it out, though I still get the exit 137 error. I actually have this

apply plugin: 'java'
test {
    maxParallelForks = 2
    maxHeapSize = '128m'
    forkEvery = 100   // helps when tests leak memory
    jvmArgs '-Xmx512m', '-Xms128m', "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap"
    afterSuite {
        System.out.print('.')
        System.out.flush()
    }
}

Do the test{} options also affect the integrationTest target? That is

$ ./gradlew :project:integrationTest

I’m asking because I added the test{} options mentioned here but the above command still fails for me with exit 137.