sbt "GC overhead limit exceeded" in CI
The JVM aborted because it was spending over 98% of its time in garbage collection while recovering less than 2% of the heap. For sbt this means the heap (-Xmx) is too small for the compile or test workload. Raise it via SBT_OPTS.
What this error means
sbt fails with "java.lang.OutOfMemoryError: GC overhead limit exceeded" during compilation or a memory-heavy test.
[error] java.lang.OutOfMemoryError: GC overhead limit exceeded
[error] (Compile / compileIncremental) java.lang.OutOfMemoryError:
GC overhead limit exceededCommon causes
Heap too small for the build
A default or low -Xmx cannot hold the working set of a large Scala compile, so the collector thrashes without freeing enough memory.
A memory-heavy test or code generation step
A test or macro/codegen step allocates heavily and outgrows the configured heap.
How to fix it
Increase the heap through SBT_OPTS
- Set a larger
-XmxinSBT_OPTSfor the sbt step. - Run sbt so the launcher applies the new heap size.
- Confirm the build completes without the GC error.
env:
SBT_OPTS: "-Xmx4g -XX:MaxMetaspaceSize=1g"Reduce peak memory pressure
Lower forked-test parallelism or split heavy modules so the working set fits the available heap.
Test / parallelExecution := falseHow to prevent it
- Set
-XmxinSBT_OPTSto match the build's real memory need. - Provision runners with headroom above the JVM heap.
- Split very large modules to cap peak memory per compile.