Maven-SonarQube Exception (java.lang.UnsupportedClassVersionError)

can anyone help me with this exception. I am getting this error while running “mvn clean -DskipTests package sonar:sonar”. I changed my java version to 11

[INFO] --- sonar-maven-plugin:3.8.0.2131:sonar (default-cli) @ rubix-plugin-jds ---
[INFO] User cache: C:\Users\shashi\.sonar\cache
[INFO] SonarQube version: 9.5.0.56709
[INFO] Default locale: "en_IN", source code encoding: "UTF-8"
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  05:47 min
[INFO] Finished at: 2022-07-02T20:02:11+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.8.0.2131:sonar (default-cli) on project rubix-plugin-jds: Execution de
fault-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.8.0.2131:sonar failed: An API incompatibility was encountered while executing org.s
onarsource.scanner.maven:sonar-maven-plugin:3.8.0.2131:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformatio
n 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
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:3.8.0.2131
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/shashi/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.8.0.2131/sonar-maven-plugin-3.8.0.2131.jar
[ERROR] urls[1] = file:/C:/Users/shashi/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[2] = file:/C:/Users/shashi/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[3] = file:/C:/Users/shashi/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
[ERROR] urls[4] = file:/C:/Users/shashi/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.16.0.226/sonar-scanner-api-2.16.0.226.jar
[ERROR] urls[5] = file:/C:/Users/shashi/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>com.fluentretail:rubix-plugin-jds:3.5.12.10, parent: ClassRealm[maven.api, parent: null]]]
[ERROR]
[ERROR] -----------------------------------------------------

Hi,

means the sonar:sonar goal of your Maven build runs with Java 8, but needs to run with Java 11.

Gilbert

To complement @Rebse’s answer, here is the documentation on requirements in the Scanner Environment.