Issue with Sonar Maven scan when using Project's specific JDK

Sonar Version 9.5 (build 56709)
Our Code will compile with JDK8

Hi team,

Since our code will compile with JDK8 my bamboo pipeline is configured with below arguments but still build is getting failed with java.lang.UnsupportedClassVersionError error.

clean install sonar:sonar -X -Dsonar.projectName="xxxxxx" -Dsonar.ws.timeout=60000 -Dsonar.host.url=https://xxxxxxxxx/sonar -Dsonar.login=xxxxx -Dsonar.password=xxxxxx -Dsonar.java.jdkHome=/opt/jdk-11.0.1

Note: My bamboo Maven task will use JDK8 to compile the build and scanner should use -Dsonar.java.jdkHome=/opt/jdk-11.0.1 for scanning

As per below documentation its clear that if we have using MAVEN it will hanlde Project’s specific JDK automatically when we use sonar.java.jdkHome argument.

https://docs.sonarqube.org/latest/analysis/languages/java/#header-2

uild	17-Aug-2022 10:17:49	[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project v3-product: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
build	17-Aug-2022 10:17:49	[ERROR] -----------------------------------------------------
build	17-Aug-2022 10:17:49	[ERROR] realm =    plugin>org.codehaus.mojo:sonar-maven-plugin:3.9.1.2184
build	17-Aug-2022 10:17:49	[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
build	17-Aug-2022 10:17:49	[ERROR] urls[0] = file:/home/********/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.1.2184/sonar-maven-plugin-3.9.1.2184.jar
build	17-Aug-2022 10:17:49	[ERROR] urls[1] = file:/home/********/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
build	17-Aug-2022 10:17:49	[ERROR] urls[2] = file:/home/********/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
build	17-Aug-2022 10:17:49	[ERROR] urls[3] = file:/home/********/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
build	17-Aug-2022 10:17:49	[ERROR] urls[4] = file:/home/********/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.16.2.588/sonar-scanner-api-2.16.2.588.jar
build	17-Aug-2022 10:17:49	[ERROR] urls[5] = file:/home/********/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
build	17-Aug-2022 10:17:49	[ERROR] Number of foreign imports: 1
build	17-Aug-2022 10:17:49	[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
build	17-Aug-2022 10:17:49	[ERROR] 
build	17-Aug-2022 10:17:49	[ERROR] -----------------------------------------------------
build	17-Aug-2022 10:17:49	[ERROR] -> [Help 1]
build	17-Aug-2022 10:17:49	org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project v3-product: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Hey there.

sonar.java.jdkHome feeds data to the analysis, but does not configure what JVM is used for the analysis.

You’ll need to break out your build/analysis into two separate Maven steps. Take a look at the documentation on Scanner Environment for examples.

Thanks @Colin for your response.

I will give try as per your suggestions and update you with my results.

Thanks,
Sunil Palugula