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

My Java project written and compiled in 1.8 through Maven. I am getting the following error when I try to analyze my code using sonar-maven-plugin Ver. 3.9.1.2184 for SonarQube 9.9 LTS.

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project cmdb-nettopo-ftp-c1bb-connector: 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

I am using below command in my maven.groovy script -

sh “mvn sonar:sonar -Dsonar.qualitygate.wait=true -Dsonar.host.url=http://x.x.x.x:9000 -Dsonar.java.jdkHome=/data/jenkins_home/tools/jdk-11 -f $targetDir”

and my jenkins build pipeline is already set to jdk-11 as shown above.

My sonarqube 9.9 LTS inside docker container and java version 17 there.
How to troubleshoot this problem? Shall I need to make any changes in pom.xml file?
Please provide the specific solution.

This my example pom.xml file -

<?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>
  <parent>
    <groupId>com.xxx.maven</groupId>
    <artifactId>mo-base-parent</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <relativePath></relativePath>
  </parent>

  <groupId>com.xxx.eaa</groupId>
  <artifactId>eaa-cmdb-nettopo-ftp-c1bb-connector</artifactId>
  <version>2.8-SNAPSHOT</version>
  <packaging>docker</packaging>
  <properties>
    <container.tomcat.home>/opt/tomcat</container.tomcat.home>
    <eaa.product.name>eaa-proassure-connector</eaa.product.name>
    <sonar.branch>2.8</sonar.branch>
    <sonar.build-stability.url>Jenkins:http://abc.example.com:8080/jenkins/job/${project.artifactId}-${sonar.branch}/</sonar.build-stability.url>
    <webapp.artifact.version>${webapp.version}-SNAPSHOT</webapp.artifact.version>
    <webapp.artifactId>cmdb-nettopo-ftp-c1bb-connector</webapp.artifactId>
    <webapp.groupId>com.xxx.ea</webapp.groupId>
    <webapp.version>2.8</webapp.version>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>${maven-antrun-plugin.version}</version>
        <executions>
          <execution>
            <id>create-docker-logdirs</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <target>
                <mkdir dir="target/docker-logs"></mkdir>
                <mkdir dir="target/xxx-logs"></mkdir>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>${maven-resources-plugin.version}</version>
        <executions>
          <execution>
            <id>docker-copy-base</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <outputDirectory>${basedir}/target/docker-content/</outputDirectory>
              <resources>
                <resource>
                  <includes>
                    <include>*</include>
                  </includes>
                  <directory>${basedir}/src/main/docker/</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <id>docker-copy-resources</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <outputDirectory>${basedir}/target/docker-content/</outputDirectory>
              <resources>
                <resource>
                  <includes>
                    <include>*.properties</include>
                    <include>*.sh</include>
                  </includes>
                  <directory>${basedir}/src/main/resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>retrieve-apps-archives</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>false</overWriteSnapshots>
              <overWriteIfNewer>true</overWriteIfNewer>
              <stripVersion>true</stripVersion>
              <excludeTransitive>true</excludeTransitive>
              <artifactItems>
                <artifactItem>
                  <groupId>com.xxx.ea</groupId>
                  <artifactId>${webapp.artifactId}</artifactId>
                  <version>${webapp.artifact.version}</version>
                  <overWrite>false</overWrite>
                  <type>war</type>
                  <outputDirectory>${project.build.directory}/docker-content</outputDirectory>
                  <includes>**/*</includes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
		   <execution>
            <id>retrieve-apps-tpp</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>false</overWriteSnapshots>
              <overWriteIfNewer>true</overWriteIfNewer>
              <stripVersion>true</stripVersion>
              <excludeTransitive>true</excludeTransitive>
              <artifactItems>
                <artifactItem>
                  <groupId>com.xxx.xxx.cntr.dgta</groupId>
                  <artifactId>dgta_bb_ftp_nc1</artifactId>
                  <version>LATEST</version>
                  <classifier>tpp</classifier>
                  <type>tpp</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/docker-content</outputDirectory>
                  <includes>**/*</includes>
                  <destFileName>dgta_bb_ftp_nc1.tpp</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Hey there

This doesn’t influence the version of Java used by Maven (and thus the SonarScanner) – which appears to be Java 8. Take a look at the documentation on Scanner Environment.

1 Like