# java.lang.OutOfMemoryError: Java heap space

- **ID:** `cicd/jenkins-maven-compile-out-of-memory`
- **Domain:** cicd
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Jenkins 2.440 | active | — | — |
| Maven 3.9.6 | active | — | — |
| OpenJDK 17 | active | — | — |

## Workarounds

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' }`.** (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' }`.
   ```
2. **Add `<forkCount>1</forkCount>` and `<argLine>-Xmx1g</argLine>` to the Maven Surefire plugin configuration in pom.xml to limit test forking memory.** (80% success)
   ```
   Add `<forkCount>1</forkCount>` and `<argLine>-Xmx1g</argLine>` to the Maven Surefire plugin configuration in pom.xml to limit test forking memory.
   ```

## Dead Ends

- **** — 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. (95% fail)
- **** — Disabling necessary plugins breaks the build; memory issues are usually due to the compiler or surefire plugin handling large codebases, not plugin count. (70% fail)
