Sonarcloud in Java 8

Hi, i want ask a question about new sonarcloud analyzer. I will tell my Environemnt

  • Sonarcloud
  • CI/CD Tools: Azure Pipelines
  • Build: Maven Task

My pipeline:

- task: Bash@3
  displayName: 'Use JDK11 by default'
  inputs:
    targetType: 'inline'
    script: |
      echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME_11_X64"
- task: Maven@3
  displayName: Maven Build
  inputs:
    mavenPomFile: '$(Agent.BuildDirectory)/code/pom.xml'
    goals: '-s $(Agent.BuildDirectory)/tool/tool/settings.xml -Dmaven.test.skip=true package'
    options: '$(MAVEN_OPTS)'
    publishJUnitResults: false
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    mavenVersionOption: 'Default'
    mavenAuthenticateFeed: true
    effectivePomSkip: false
    sonarQubeRunAnalysis: true

My application build use Java 8, but sonarcloud analyzer must running in Java 11. I have try any suggestin like to change the default JDK to JDK 11, but still showing failed message like below

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project delivery-parent: 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

If i change the maven task with sonarQubeRunAnalysis: true and use sonarcloud Analyze task, the output show warning message like this

##[warning][SQ] When using Maven or Gradle, don't use the analyze task but instead tick the 'SonarQube' option in the Maven/Gradle task to run the scanner as part of the build.

Please give me a suggestion :slight_smile:

Hey there.

jdkVersionOption is setting JAVA_HOME – it’s not doing the equivilant of setting maven.compiler.source or maven.compiler.target in your pom.xml. So effectively after setting JAVA_HOME to Java 11 in your bash script you’re kicking it back to Java 8 in your maven task.

So it all depends on what your goal is – to have everything run by Java 11 and target Java 8? Or to build with Java 8 and run SonarQube analysis with Java 11. Both are valid – the former will require edits to your pom.xml to target the right Java version, while the latter will require seperating your build / analysis steps into seperate tasks.

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