I constantly run into an OutOfMemoryError when trying to run mvn sonar:sonar in a Gitlab CI pipeline of a multi-module Maven project:
510834 [INFO] Execute PMD 6.45.0 (done) | time=58039ms
511499 [INFO] ------------------------------------------------------------------------
511499 [INFO] Reactor Summary for m***e 5.7.0-SNAPSHOT:
511500 [INFO]
511500 [INFO] m***e ....................................... FAILURE [04:42 min] (<-- parent module!)
511500 [INFO] s***n ................................... SUCCESS [ 1.879 s]
...
511510 [INFO] s***e ................................. SUCCESS [ 9.232 s]
511510 [INFO] ------------------------------------------------------------------------
511510 [INFO] BUILD FAILURE
511510 [INFO] ------------------------------------------------------------------------
511510 [INFO] Total time: 08:30 min
511511 [INFO] Finished at: 2023-01-16T12:12:50Z
511511 [INFO] ------------------------------------------------------------------------
511538 [ERROR] Java heap space -> [Help 1]
511538 [ERROR]
511538 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
511541 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
511541 [ERROR]
511541 [ERROR] For more information about the errors and possible solutions, please read the following articles:
511542 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
The very first thing that I tried was different variants of what’s mentioned in OutOfMemoryError - Apache Maven - Apache Software Foundation.
In my .gitlab-ci.yml
there’s the test:sonar job which is defined as follows:
...
test:sonar:
image: registry.m***/maven-docker:latest
stage: test
only:
- schedules
variables:
MAVEN_OPTS: "-Xmx1024m"
script:
- mvn clean install -DskipTests sonar:sonar
I also tried this variation:
...
test:sonar:
image: registry.m***/maven-docker:latest
stage: test
only:
- schedules
script:
- export MAVEN_OPTS="-Xmx1024m" && mvn clean install -DskipTests sonar:sonar
This maven-docker
image is based upon the image docker:19.03-dind
plus installing Java, Maven and the settings.xml pointing to our SonarQube server.
Versions used:
- openjdk version “11.0.9” 2020-10-20
- OpenJDK Runtime Environment (build 11.0.9+11-alpine-r1)
- OpenJDK 64-Bit Server VM (build 11.0.9+11-alpine-r1, mixed mode)
- Apache Maven 3.6.3
- SonarQube: * Community Edition Version 8.9.9 (build 56886)
- sonar-maven-plugin-3.9.1.2184
It always results in a java process running within the gitlab-ci job as follows:
/usr/bin/java -Xmx1024m -Xmx512m -classpath /usr/share/java/maven-3/boot/plexus-classworlds-2.6.0.jar ... clean install -DskipTests sonar:sonar
That second “-Xmx” parameter always overwrites my settings and resets max heap space again to 512MB.
Can anyone tell me where that -Xmx512m parameter comes from?
Or how to actually set that parameter correctly without it getting overwritten again?