Out of Memory Error in Jenkins Sonar Scanner

When trying to analyze code using Jenkins sonar scanner plugin below out of memory heap error comes.

#12 247.3 [INFO] ------------- Run sensors on module pe-scheduler-service_release
#12 247.4 [INFO] Load metrics repository
#12 247.4 [INFO] Load metrics repository (done) | time=44ms
#12 248.7 [INFO] Sensor JavaSensor [java]
#12 248.7 [INFO] Configured Java source version (sonar.java.source): 8
#12 248.7 [INFO] JavaClasspath initialization
#12 248.7 [INFO] JavaClasspath initialization (done) | time=41ms
#12 248.7 [INFO] JavaTestClasspath initialization
#12 248.7 [INFO] JavaTestClasspath initialization (done) | time=7ms
#12 248.7 [INFO] Server-side caching is enabled. The Java analyzer will not try to leverage data from a previous analysis.
#12 248.7 [INFO] Using ECJ batch to parse 111 Main java source files with batch size 120 KB.
#12 249.0 [INFO] Starting batch processing.
#12 249.7 [INFO] The Java analyzer cannot skip unchanged files in this context. A full analysis is performed for all files.
#12 264.2 [INFO] 24% analyzed
#12 274.2 [INFO] 24% analyzed
#12 284.2 [INFO] 24% analyzed
#12 294.8 [INFO] 24% analyzed
#12 306.5 [INFO] 24% analyzed
#12 317.6 [INFO] 24% analyzed
#12 328.5 [INFO] 24% analyzed
#12 339.2 [INFO] 24% analyzed
#12 349.7 [INFO] 24% analyzed
#12 360.3 [INFO] 24% analyzed
#12 407.8 Exception in thread “Report about progress of Java AST analyzer” java.lang.OutOfMemoryError: Java heap space
#12 407.8 at org.sonar.java.ProgressMonitor.run(ProgressMonitor.java:80)
#12 407.8 at java.base/java.lang.Thread.run(Thread.java:834)
#12 419.1 [INFO] Did not optimize analysis for any files, performed a full analysis for all 28 files.
#12 419.1 [WARNING] Use of preview features have been detected during analysis. Enable DEBUG mode to see them.
#12 419.1 [INFO] ------------------------------------------------------------------------
#12 419.1 [INFO] BUILD FAILURE

SonarQube server and Jenkins are deployed as Kubernetes pods.

Versions

Jenkins: 2.319.3
Sonarqube Scanner Plugin: 2.11
Sonarqube: 9.9.1CE

Seems like you need to up the memory available to the scanner.

Any suggestion on how to do this on jenkins?

You may set an evironment variable SONAR_SCANNER_OPTS via https://<yourjenkins>/manage/configure

2024-02-20_12h44_05