using sonarcloud for junit analysis fails when the source code version is jdk1.8 but sonarcloud uses jdk17

148 Views Asked by At

This is the error message getting when the maven verify command is executed from azure pipeline Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.10.0.2594:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.10.0.2594: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 expecting my code should get built and should be successfully analyzed when calling the sonarcloud from the azure pipeline

1

There are 1 best solutions below

0
Ziyang Liu-MSFT On

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

You can upgrade your JDK to JDK11 or downgrade SonarQube to 8.9. To use JDK11 in the DevOps pipeline, you can try the suggestions below.

  1. Use image Ubuntu 20.04 or Ubuntu 22.04 to run your pipeline. The default version of Java JDK is 11.0.21+9. See the software in the images.
  2. Select Java version manually when using maven task. SetjavaHomeOption: 'JDKVersion' and jdkVersionOption: '1.11'.
    - task: Maven@3
      displayName: 'Execute Maven goal'
      inputs:
        mavenPomFile: 'pom.xml'
        options: '-Dmaven.test.failure.ignore=true'
        mavenOptions: '-Xmx3072m'
        mavenVersionOption: 'Default'
        javaHomeOption: 'JDKVersion'
        jdkVersionOption: '1.11'
        jdkArchitectureOption: 'x64'
        publishJUnitResults: true
        mavenAuthenticateFeed: false
        effectivePomSkip: false
        sonarQubeRunAnalysis: true
        sqMavenPluginVersionChoice: 'latest'
        codeCoverageToolOption: 'JaCoCo'
        testResultsFiles: '**/TEST-*.xml'
        goals: 'verify'