Sonar analysis is failing for java 8 project

Hii, I am new with sonar and I am trying to use sonar analysis for my java 8 project. I am using gitlab ci for CI, and I am getting following error when the gitlab pipeline is failing,
sonar version : 9.9.3
java version : 17 (on the server on which sonar is running)
java version : 8 (project)

following is the error I am facing

error : [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin: (default-cli) on project test-sonar: Execution 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.0
[732]([ERROR] --------------------------
[733]([ERROR] realm = plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:
[734]([ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[735]([ERROR] urls[0] = file:/root/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/
[736]([ERROR] urls[1] = file:/root/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[737]([ERROR] urls[2] = file:/root/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[738]([ERROR] urls[3] = file:/root/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
[739]([ERROR] urls[4] = file:/root/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/
[740]([ERROR] urls[5] = file:/root/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar

[741]([ERROR] Number of foreign imports: 1

[742]([ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]


[744]([ERROR] -----------------------------------------------------


[746]([ERROR] -> [Help 1]


[748]([ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[749]([ERROR] Re-run Maven using the -X switch to enable full debug logging.


[751]([ERROR] For more information about the errors and possible solutions, please read the following articles:

[752]([ERROR] [Help 1]

[754]( Job failed: exit code 1

following is the gitlab-ci.yml file i am using:

  image: maven:3.5.2-jdk-8  # Use the specific Maven and Java version you need
    GIT_DEPTH: 0
    key: "${CI_JOB_NAME}"
      - .sonar/cache
    - mvn -version
    - echo $JAVA_HOME
    - mvn clean install -U
    - mvn verify sonar:sonar -Dsonar.projectKey=xxxxxxxx
      - target/sonar
  allow_failure: false
    - feature/
    - merge_requests
    - testBranch

and pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
			<!-- Configure the SonarQube Scanner Maven plugin -->
				<!-- Use the desired version -->

Can somebody help me with this…?

Hey there.

You’ll need to use an image with Java 11 (at a minimum) as documented in the Scanner Environment documentation.

What about giving maven:3.9.6-eclipse-temurin-11 a try?

Hey Colin,
I tried with the image you suggest , but I got the same error.

I found the solution to my problem by using following Docker image " maven:3.9.3-eclipse-temurin-17" .
and I also need to change the sonar-maven-plugin version.
Thanks for the help

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