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
    versionSpec: '11'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

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

- task: SonarCloudPrepare@1
    SonarCloud: 'SonarCloud_Org'
    organization: 'Organisation_Name'
    projectKey: ${{parameters.repoName}}
    projectName: ${{parameters.repoName}} $[replace(variables['Build.SourceBranch'], 'refs/heads/', '')]
    extraProperties: |$(Agent.BuildDirectory)/${{parameters.repoName}}/build/classes/java/main$(Agent.BuildDirectory)/${{parameters.repoName}}/build/libs/*.jar

- task: Gradle@2
    gradleWrapperFile: '$(Agent.BuildDirectory)/${{parameters.repoName}}/gradlew'
    workingDirectory: $(Agent.BuildDirectory)/${{parameters.repoName}}
    options: ''
    tasks: 'build'
    publishJUnitResults: true
    testResultsFiles: '**/TEST-*.xml'
    javaHomeOption: 'JDKVersion'
    sonarQubeRunAnalysis: true
    sqGradlePluginVersionChoice: 'specify'
    sonarQubeGradlePluginVersion: '2.8'

@sonarsourcers requesting support on 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