SonarQube 9 with Azure DevOps Pipeline Java 8 Code

Need some help with SonarQube 9 that now requires Java 11

  • Using SonarQube 9 with Azure DevOps Yaml Pipeline
  • Maven@3 task for Sonar requires Java 11, yet Code must be compiled with Java 8
  • How do I compile with Java 8 and run the scanner against Java 11 in one task
  • toolOption jaCoCo adds clean phase to Maven goal, removes all previously compiled code

DevOps Pipeline looks roughly like this:

...
- task: Maven@3
  jdkVersionOption: '1.11'
  goals: 'sonar:sonar'
  codeCoverageToolOption: 'jaCoCo'
  sonarQubeRunAnalysis: true
...
- task: SonarQubeAnalyze@4

- task: SonarQubePublish@4
  inputs:
    pollingTimeoutSec: '400'

Anyone have an idea how to achieve this? Is there an alternative solution that does basically the same?

Maybe I have to specify my question more clearly. I have to run the Maven@3 task with jdk 1.8 but the SonarScanner needs 1.11.

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar (default-cli) on project : Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155: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 somehow have to set sonar.java.jdkHome=/usr/lib/jvm/jdk-11 for the scanner.

Hi @sebsch,

If I understand well, you need jdk8 to build your project and you need jdk11 to run SonarScanner.

If this is the case, then you are right to use sonar.java.jdkHome. You can build your project with jdk8. Then when executing analysis, you need to run SonarScanner with this property pointing to jdk8, i.e. sonar.java.jdkHome=/usr/lib/jvm/jdk-8.

You can find the doc here.

Best regards,
Fan

Hi @Fan_Yang

I solved it with compiling in JDK8 and moving the sonar phase to another task with JDK 11. I just had issues when activating jacoco in the Maven@3 task which creates a VSTSReport but not the target/site folders.

- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    jdkVersionOption: '1.8'
   goal: clean package
   # do not use jacoco here

- task: Bash@3
  displayName: 'Run sonar:sonar'
  inputs:
    targetType: 'inline'
    script: |
      export JAVA_HOME=/usr/lib/jvm/jdk-11
      mvn sonar:sonar

- task: SonarQubePublish@4
  inputs:
    pollingTimeoutSec: '400'

Thanks for the help!

1 Like

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