Maven: Resolving Out of Memory Heap space error

Please suggest different options.

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    Sonarqube: 8.9.10. Scanner:CLI 4.0 Maven Plugin: 3.9.1

  • what are you trying to achieve
    We want to resolve out of memory heap space issue. We were not able to find a right place to define Maven_Opts or Scanner_Opts. Added the scripting blocks we used in the next question. There are many files in the codebase to be scanned hence this out of memory error.

  • what have you tried so far to achieve this

sonar container block:

                        stage('Analyze: SonarQube') {
                                                        
                            container('maven') {
                                withSonarQubeEnv('SonarQube') {
                                    warnError('SonarQube Quality Gate FAILED') {
                                        sh """
                                            mvn --activate-profiles pipeline \
                                                --batch-mode \
                                                --define revision=$deployVersion \
                                                --define server.username=\$AUSER \
                                                --define server.password=\$APW \
                                                sonar:sonar
                                            unset MAVEN_OPTS
                                        """
                                    }
                                }
                            }
                            milestone 30
                        }

We tried setting Maven_Opts with export option in the above block. Also defining it in the container template.

 containerTemplate(
                            name: 'sonar',
                            image: 'sonarsource/sonar-scanner-cli:4',
                            envVars: [
                                containerEnvVar(key: "SONAR_SCANNER_OPTS", value: "-Xmx10240m" )
                                ],
                            command: 'sleep',
                            args: '1h'
                    )

Hi,

Welcome to the community!

In your first block I see you unsetting MAVEN_OPTS, but I don’t see you setting it. Maybe put that right before you invoke mvn?

 
HTH,
Ann

Hi Ann,

Thanks for your reply,
We had declare vaiables like below,

stage('Analyze: SonarQube') {
	container('maven') {
		withSonarQubeEnv('SonarQube') {
			warnError('SonarQube Quality Gate FAILED') {
				sh """
					export MAVEN_OPTS='-Xmx10240m -XX:MaxPermSize=10240m'
					mvn --activate-profiles pipeline \
						--batch-mode \
						--define revision=$deployVersion \
						--define server.username=\$AUSER \
						--define server.password=\$APW \
						clean install sonar:sonar
					unset MAVEN_OPTS
				"""
			}
		}
	}
	milestone 30
}

But during the pipeline build its not taking what we give.

Thanks
Harshavardhan Reddy S

Hi Harshavardhan,

Welcome to the community!

I guess you work with the OP?

Can you share your analysis log, redacted as necessary?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann