cicd system_error ai_generated true

java.lang.OutOfMemoryError: Java heap space

ID: cicd/jenkins-maven-compile-out-of-memory

Also available as: JSON · Markdown · 中文
82%Fix Rate
87%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Jenkins 2.440 active
Maven 3.9.6 active
OpenJDK 17 active

Root Cause

Maven build in Jenkins exhausted the Java heap space, typically due to insufficient memory allocation for the JVM or a memory leak in the build plugins.

generic

中文

Jenkins 中的 Maven 构建耗尽了 Java 堆空间,通常是由于 JVM 内存分配不足或构建插件中存在内存泄漏。

Official Documentation

https://maven.apache.org/configure.html

Workarounds

  1. 85% success Increase Maven's JVM heap via MAVEN_OPTS: `export MAVEN_OPTS="-Xmx2g -Xms512m"` before the build step, or configure in Jenkins pipeline: `withEnv(['MAVEN_OPTS=-Xmx2g']) { sh 'mvn clean install' }`.
    Increase Maven's JVM heap via MAVEN_OPTS: `export MAVEN_OPTS="-Xmx2g -Xms512m"` before the build step, or configure in Jenkins pipeline: `withEnv(['MAVEN_OPTS=-Xmx2g']) { sh 'mvn clean install' }`.
  2. 80% success Add `<forkCount>1</forkCount>` and `<argLine>-Xmx1g</argLine>` to the Maven Surefire plugin configuration in pom.xml to limit test forking memory.
    Add `<forkCount>1</forkCount>` and `<argLine>-Xmx1g</argLine>` to the Maven Surefire plugin configuration in pom.xml to limit test forking memory.

中文步骤

  1. Increase Maven's JVM heap via MAVEN_OPTS: `export MAVEN_OPTS="-Xmx2g -Xms512m"` before the build step, or configure in Jenkins pipeline: `withEnv(['MAVEN_OPTS=-Xmx2g']) { sh 'mvn clean install' }`.
  2. Add `<forkCount>1</forkCount>` and `<argLine>-Xmx1g</argLine>` to the Maven Surefire plugin configuration in pom.xml to limit test forking memory.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    The Maven build runs as a separate process on the agent, not on the master; increasing master heap does not affect the build agent's JVM.

  2. 70% fail

    Disabling necessary plugins breaks the build; memory issues are usually due to the compiler or surefire plugin handling large codebases, not plugin count.