Skip to content
Latchkey

Build "Killed" (Exit 137) During Maven/Gradle - OOM-Kill in CI

The build process was SIGKILLed by the kernel OOM killer (exit 137) because the JVM, plus forked workers and the OS, exceeded the runner memory. There is no Java stack trace - the process was terminated from outside.

What this error means

A build that was progressing prints a bare Killed and the step exits with code 137. No OutOfMemoryError is logged because the kernel, not the JVM, ended the process.

shell
> Task :app:test
Killed
##[error]Process completed with exit code 137.

Common causes

Total memory exceeds the runner

The daemon/Maven JVM heap plus forked compile/test JVMs and the OS overshoot the runner RAM. The kernel kills the largest process - usually the build JVM.

Unbounded heap on a constrained runner

A large -Xmx (or default heap sized to host RAM) on a small container leaves no headroom, so the kernel OOM-kills the process under load.

How to fix it

Cap heap and parallelism to fit the runner

Bound the JVM heap and worker counts so total memory stays under the runner limit.

gradle.properties
# gradle.properties
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m
org.gradle.workers.max=2
# Maven: export MAVEN_OPTS="-Xmx2g"

Reduce forked-JVM footprint

Limit forked test JVM heap and forks so concurrent processes do not overshoot RAM.

build.gradle.kts
// Gradle
tasks.test { maxHeapSize = "1g"; maxParallelForks = 1 }

How to prevent it

  • Bound JVM heap and worker counts to the runner RAM, limit forked-JVM memory, and use a larger-RAM runner for heavy builds.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →