API incompatibility was encountered while executing org.sonarsource.scanner.maven

Recently updated the sonar analysis from JDK11 to JD17 and seeing this error

[e[1;34mINFOe[m] e[1;31mBUILD FAILUREe[m
[e[1;34mINFOe[m] e[1m------------------------------------------------------------------------e[m
[e[1;34mINFOe[m] Total time:  5.013 s
[e[1;34mINFOe[m] Finished at: 2024-01-19T00:41:58Z
[e[1;34mINFOe[m] e[1m------------------------------------------------------------------------e[m
[e[1;31mERRORe[m] Failed to execute goal e[32morg.sonarsource.scanner.maven:sonar-maven-plugin:[m e[1m(default-cli)e[m on project e[36mcms-parente[m: e[1;31mExecution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin: failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin: 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.0e[m
[e[1;31mERRORe[m] e[1;31m-----------------------------------------------------e[m
[e[1;31mERRORe[m] e[1;31mrealm =    plugin>org.codehaus.mojo:sonar-maven-plugin:[m
[e[1;31mERRORe[m] e[1;31mstrategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategye[m
[e[1;31mERRORe[m] e[1;31murls[0] = file:/var/jenkins_home/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/[m
[e[1;31mERRORe[m] e[1;31murls[1] = file:/var/jenkins_home/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jare[m
[e[1;31mERRORe[m] e[1;31murls[2] = file:/var/jenkins_home/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jare[m
[e[1;31mERRORe[m] e[1;31murls[3] = file:/var/jenkins_home/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jare[m
[e[1;31mERRORe[m] e[1;31murls[4] = file:/var/jenkins_home/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/[m
[e[1;31mERRORe[m] e[1;31murls[5] = file:/var/jenkins_home/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jare[m
[e[1;31mERRORe[m] e[1;31mNumber of foreign imports: 1e[m
[e[1;31mERRORe[m] e[1;31mimport: Entry[import  from realm ClassRealm[maven.api, parent: null]]e[m

Welcome :slight_smile:

What’s your Sonarqube version / edition ?

It seems your maven build runs on Java 8 = class file version 52.0
sonar maven plugin 3.9.1 is compiled with Java 11 = class file version 55.0

And as Java is not “backward compatible” but only “forward compatible” you get this

You need to recheck your Java installation and settings.


Appreciated Gilbert with reply back.
I’m just using this from the Shell script listed below , did changed the JDK11 to JDK17 as sonar was complainng to uplgrade to JDK17 when ever any pull request was performed . So in my case I have shell script as below.

PREVIOUS_PATH=$PATH PREVIOUS_JAVA_HOME=$JAVA_HOME JDK_17_PATH=$JDK_17/bin:$PATH echo "perform Sonar code scanning analysis with JDK 17" PATH=$JDK_17_PATH JAVA_HOME=$JDK_17 
mvn sonar:sonar -Dsonar.organization=xxxx -Dsonar.host.url=[https://sonarcloud.io](https://sonarcloud.io/) -Dsonar.login=$SONAR_LOGIN -Dsonar.projectKey=xxx_project -Dsonar.pullrequest.key=$ghprbPullId -Dsonar.pullrequest.branch=$ghprbSourceBranch -Dsonar.pullrequest.base=$ghprbTargetBranch 
mvnExit=$? if [ $mvnExit -ne 0 ]; then 
echo "Code analysis was not successful. Check logs for further details." 
exit 1 fi 

Can you please let me know where can I check Java Installations and Settings?
Currently using sonar cloud

Use printenv and java -version to check the settings.
And in case of doubt or in a restricted environment use export before starting the scanner to set Java 17 for Sonarqube analysis.

Appreciate your help Gilbert.
I did a quick troubleshooting and saw the JDK17 has to be added in the Environment Variable in Jenkins POST Build and then I did test and it worked fine.
I was able to get the solution and multiple troubleshooting and test.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.