We upgraded the SonarQube server from 7.5.4 to the next LTE version (8.9) then upgraded from there to v9.4. Our CICD is built on Jenkins. All scanning from Jenkins to SonarQube had been working prior to the upgrade. .Net jobs used Sonar Scanner for MSBuild. Java jobs use Maven.
We ran into a couple of issues after the upgrade. First, we resolved .Net Sonar Scanner issues by upgrading Sonar Scanner to v4.7 and Sonar Scanner for MSBuild to Sonar Scanner for .Net and modifying the sonar-scanner.bat file to use the embedded Java. That allows it to use Java 11 even though the Java_Home variable on the server points to Java 8.
However, we still have issues running Maven as it still has Java version issues. Here’s the error:
ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project : 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
This points to a Java mismatch. We need a way when using the Maven command to use Java 11 while the server Java_Home variable remains pointing to Java 8 which leads to the question:
How we can make a command line change so that the command for SonarQube scanning can point to Java 11 (either by using an alternate config file or some other way, while all other Maven commands aren’t effected (In other words, not changing the config making all Maven commands use Java 11.)
ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project : 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
This points to a Java mismatch. We need a way when using the Maven command to use Java 11 while the server Java_Home variable remains pointing to Java 8 which leads to the question:
How we can make a command line change so that the command for SonarQube scanning can point to Java 11 (either by using an alternate config file or some other way, while all other Maven commands aren’t effected (In other words, not changing the config making all Maven commands use Java 11.)
The command is (JOB is replacement for the actual job name):
“mvn sonar:sonar -Dsonar.projectKey=JOB -Dsonar.projectName=JOB -Dsonar.branch.name=Ola-sonar-sdds-testing --batch-mode”
Since the Jenkins server runs Java 8, we need to override that in the Maven command to point to Java 11 which is on the server in another directory. As I mentioned, Java_Home points to Java 8.
Any help is appreciated!