Gradle Task on Azure DevOps Pipeline - SonarCloud Scan - Warning | JAVA 11 build & JAVA 17 Scan

  • ALM used Azure DevOps)

  • CI system used Azure DevOps

  • Languages of the repository: Java

  • Steps to reproduce
    When the below build pipeline is executed, it gives the warning as.
    “The version of Java (11.0.21) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.”

  • Objective:
    To build the project using Java 11 & to perform the sonarscan using the gradle task with Java 17 (as sonarscan is recommending to use Java 17 to perform the code scan). However, we still need our project to be build on JAVA 11.

Azure Pipeline Code:

- task: JavaToolInstaller@0
  inputs:
    versionSpec: '11'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

- task: JavaToolInstaller@0
  inputs:
    versionSpec: '17'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'SonarCloud_Org'
    organization: 'Organisation_Name'
    projectKey: ${{parameters.repoName}}
    projectName: ${{parameters.repoName}}
    branch.name: $[replace(variables['Build.SourceBranch'], 'refs/heads/', '')]
    extraProperties: |
      sonar.java.binaries=$(Agent.BuildDirectory)/${{parameters.repoName}}/build/classes/java/main
      sonar.java.libraries=$(Agent.BuildDirectory)/${{parameters.repoName}}/build/libs/*.jar
      sonar.java.source=17
      sonar.java.jdkHome=/usr/lib/jvm/temurin-17-jdk-amd64
      sonar.gradle.skipCompile=true

- task: Gradle@2
  inputs:
    gradleWrapperFile: '$(Agent.BuildDirectory)/${{parameters.repoName}}/gradlew'
    workingDirectory: $(Agent.BuildDirectory)/${{parameters.repoName}}
    options: '-Dorg.gradle.java.home=/usr/lib/jvm/temurin-11-jdk-amd64'
    tasks: 'build'
    publishJUnitResults: true
    testResultsFiles: '**/TEST-*.xml'
    javaHomeOption: 'JDKVersion'
    sonarQubeRunAnalysis: true
    sqGradlePluginVersionChoice: 'specify'
    sonarQubeGradlePluginVersion: '2.8'

@sonarsourcers requesting support on this.

Hi,

This

doesn’t run the task with Java 17. It tells analysis that you’re writing Java 17 code.

I’m not an expert in writing ADO pipelines, but you’ll need to make sure that the SonarCloudPrepare@1 task is run with Java 17.

Alternately, I think it’s worth considering running the entire job with Java 17, and compiling down to Java 11 by specifying Java 11 as the target

 
HTH,
Ann