3

I have installed sonar locally to run it on my java project code. My this code is using java 8. My environment variable is also set to java 8 but I have installed Java 11 on my machine and set a environment variable SONAR_JAVA_PATH in my machine which is pointing to java 11. Here are my environment variables.

export SONAR_HOME=/opt/homebrew/Cellar/sonar-scanner/4.7.0.2747/libexec
export SONAR=$SONAR_HOME/bin
export PATH=$SONAR:$PATH

export SONAR_JAVA_PATH=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
export PATH=$SONAR_JAVA_PATH:$PATH

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
export PATH=${JAVA_HOME}/bin:${PATH}
export PATH

When I run following command in my root directory

   mvn clean verify sonar:sonar \
  -Dsonar.projectKey=tirebattery-orderprocessing-svcs \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.login=sqp_17296fe6fac85ebd5f0c0f0490b78216b5ea7140

It throws following error

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 recognises class file versions up to 52.0

I am very confused about this error. In my IntelliJ how can i build code in Java 8 and run sonar on java 11 ? In few previous answers I red to edit wrapper.conf file but in MAC there is no such file created after installation of sonar through Brew. Can anyOne kindly explain me in simple words that why this issue is happening, What is the root cause and what changes I have to make to my POM to resolve this issue. Here is my POM.xml file

<?xml version="1.0" encoding="UTF-8"?>

4.0.0

<groupId>com.sams.clubops.orderprocessing</groupId>
<artifactId>tbcorderprocessing</artifactId>
<version>1.8.3</version>
<packaging>jar</packaging>

<name>tbcorderprocessing</name>
<description>Purchase order processing services</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <azure.version>2.0.5</azure.version>
    <java.version>1.8</java.version>
    <camel.version>2.20.1</camel.version>
    <spring.boot.version>2.7.2</spring.boot.version>
    <swagger2.version>2.9.2</swagger2.version>
    <tbc-common.version>1.8.4-SNAPSHOT</tbc-common.version>
</properties>
<distributionManagement>
    <repository>
        <id>pangaea_releases</id>
        <name>xyz Releases</name>
        <url>http://gec-maven-nexus.xyz.com/nexus/content/repositories/pangaea_releases</url>
    </repository>
    <snapshotRepository>
        <id>pangaea_snapshots</id>
        <name>xyz Snapshots</name>
        <url>http://gec-maven-nexus.xyz.com/nexus/content/repositories/pangaea_snapshots</url>
    </snapshotRepository>
</distributionManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
    </dependency>

    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>${spring.boot.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-spring-data-cosmos</artifactId>
        <version>3.25.0</version>
    </dependency>

    <!-- Added for SQL Server Connection 12/07 -->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.retry/spring-retry -->
    <dependency>
        <groupId>org.springframework.retry</groupId>
        <artifactId>spring-retry</artifactId>
        <version>1.2.4.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-aop -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
        <version>${spring.boot.version}</version>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>

  <dependency>
        <groupId>com.sams.event.horizon</groupId>
        <artifactId>evclient</artifactId>
        <version>0.0.60</version>
      <exclusions>
          <exclusion>
              <groupId>com.google.code.gson</groupId>
              <artifactId>gson</artifactId>
          </exclusion>
      </exclusions>
   </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>${spring.boot.version}</version>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.197</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>${swagger2.version}</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>${swagger2.version}</version>
        <scope>compile</scope>
    </dependency>
    <!--TBC Commons dependency-->
    <dependency>

        <groupId>com.sams.clubops.tbc</groupId>
        <artifactId>tbc-common</artifactId>
        <version>${tbc-common.version}</version>
    </dependency>

    <!--        EVENT HUB EVENT PROCESSOR-->
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-eventhubs</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-eventhubs-eph</artifactId>
        <version>3.0.2</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-servicebus</artifactId>
        <version>1.2.11</version>
    </dependency>
    <dependency>
        <groupId>org.apache.directory.studio</groupId>
        <artifactId>org.apache.commons.collections</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>applicationinsights-logging-logback</artifactId>
        <version>2.5.1</version>
    </dependency>

    <dependency>
        <groupId>com.sams.mth</groupId>
        <artifactId>common</artifactId>
        <version>3.0.2</version>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
        <version>2.1.7</version>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-inline</artifactId>
        <version>3.8.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources/docker</directory>
                                <includes>
                                    <include>Dockerfile</include>
                                    <include>sshd_config</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>src/main/resources/docker</directory>
                                <includes>
                                    <include>startup.sh</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>src/main/resources/docker</directory>
                                <includes>
                                    <include>proxy-intranet-ref-app.conf</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>src/main/resources/keystore</directory>
                                <includes>
                                    <include>stage-extes-replenishment.crt</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>src/main/resources/docker</directory>
                                <includes>
                                    <include>stage-event-horizon-eus.cld.samsclub.com.cer</include>
                                    <include>stage-event-horizon-wus.cld.samsclub.com.cer</include>
                                    <include>stage-event-horizon-station.cld.samsclub.com.cer</include>
                                    <include>event-horizon-eus.cld.samsclub.com.cer</include>
                                    <include>event-horizon-wus.cld.samsclub.com.cer</include>
                                    <include>event-horizon-station.cld.samsclub.com.cer</include>
                                    <include>stage-extes-replenishment.wal-mart.com.cer</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.coveo</groupId>
            <artifactId>fmt-maven-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <displayLimit>10</displayLimit>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.7.201606060606</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jacoco-check</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    <configuration>
                        <excludes>
                            <exclude>com/sams/clubops/orderprocessing/object/**/*</exclude>
                            <exclude>com/sams/clubops/orderprocessing/repository/document/*</exclude>
                            <exclude>**/*EventConsumerManager.class</exclude>
                            <exclude>**/*EventProcessHostObjFactory.class</exclude>
                            <exclude>**/*DotComOrdersPoLogRepo.class</exclude>
                            <exclude>**/*OrderProcessingCosmosConfig.class</exclude>
                        </excludes>
                        <rules>
                            <rule>
                                <element>BUNDLE</element>
                                <limits>
                                    <limit>
                                        <counter>LINE</counter>
                                        <value>COVEREDRATIO</value>
                                        <!--CHange it back to 80-->
                                        <minimum>0.83</minimum>
                                    </limit>
                                </limits>
                            </rule>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <testFailureIgnore>false</testFailureIgnore>
            </configuration>
        </plugin>
    </plugins>
</build>
Umair
  • 585
  • 3
  • 9
  • 21

2 Answers2

4

Java used to run SonarScanner - Java 8 in SonarQube 8.9, Java 11 in SonarQube 9.0 and higher

Either upgrade your JDK to JDK11 or downgrade SonarQube to 8.9

Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38
0

SonarQube 9.8 has stopped supporting Scanner tool 3.9.1 for Java 8 version. So you need to use SonarQube version 8.9 or below for analysis. Or you can refer to the following but may still not work with the new Scanner tool version:

mvn sonar:sonar 
-Dsonar.login=xxxxxxxxxxxxx
-Dsonar.host.url=http://localhost:9001/sonarqube 1
-Dsonar.java.jdkHome=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home

Reference from: https://community.sonarsource.com/t/java-versions-in-sonarqube/67551

Fedor
  • 17,146
  • 13
  • 40
  • 131