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:3.7.0.1746:sonar (default-cli) on project test-sonar: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746: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
[732](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L732)[ERROR] --------------------------
[733](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L733)[ERROR] realm = plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746
[734](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L734)[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[735](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L735)[ERROR] urls[0] = file:/root/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.7.0.1746/sonar-maven-plugin-3.7.0.1746.jar
[736](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L736)[ERROR] urls[1] = file:/root/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[737](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L737)[ERROR] urls[2] = file:/root/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[738](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L738)[ERROR] urls[3] = file:/root/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
[739](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L739)[ERROR] urls[4] = file:/root/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.14.0.2002/sonar-scanner-api-2.14.0.2002.jar
[740](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L740)[ERROR] urls[5] = file:/root/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar

[741](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L741)[ERROR] Number of foreign imports: 1

[742](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L742)[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]

[743](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L743)[ERROR]

[744](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L744)[ERROR] -----------------------------------------------------

[745](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L745)[ERROR]

[746](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L746)[ERROR] -> [Help 1]

[747](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L747)[ERROR]

[748](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L748)[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[749](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L749)[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[750](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L750)[ERROR]

[751](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L751)[ERROR] For more information about the errors and possible solutions, please read the following articles:

[752](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L752)[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

[754](http://gitlab.sapidblue.in/digital-platform/test-sonar/-/jobs/591#L754)ERROR: Job failed: exit code 1

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

sonarqube-check:
  image: maven:3.5.2-jdk-8  # Use the specific Maven and Java version you need
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
    GIT_DEPTH: 0
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - mvn -version
    - echo $JAVA_HOME
    - mvn clean install -U
    - mvn verify sonar:sonar -Dsonar.java.jdkHome=/usr/lib/jvm/jdk8/ -Dsonar.projectKey=xxxxxxxx
  artifacts:
    paths:
      - target/sonar
  allow_failure: false
  only:
    - feature/
    - merge_requests
    - testBranch

and pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project
	xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>groupId</groupId>
	<artifactId>test-sonar</artifactId>
	<version>1.0-SNAPSHOT</version>
	<properties>
		<sonar.qualitygate.wait>true</sonar.qualitygate.wait>
		<java.version>1.8</java.version>
	</properties>
	<build>
		<plugins>
			<!-- Configure the SonarQube Scanner Maven plugin -->
			<plugin>
				<groupId>org.sonarsource.scanner.maven</groupId>
				<artifactId>sonar-maven-plugin</artifactId>
				<version>3.7.0.1746</version>
				<!-- Use the desired version -->
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.0</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

Can somebody help me with this…?
Thanks
Astitva

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.