I am trying to setup scanning in Azure DevOps to point to SonarCloud. I am getting the warning about the project being scanned using Java 11, and to use Java 17.
My build agents have Java 17 installed and the proper environment variable ( JAVA_HOME_17_X64 ), however, the tasks are still being executed using Java 11.
Looking at the code for the VSTS extension, the jdkVersion looks to be passed in correctly, but is completely ignored in the analyze function. JAVA_HOME_11_X64 is ALWAYS used to set the Java home.
I believe this extension needs updated both listen to the jdkversion input AND to default to Java 17.
I can’t reproduce this on my end. This is how my pipeline looks like:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud'
organization: 'fiveshotsofespresso'
scannerMode: 'MSBuild'
projectKey: 'fiveshotsofespresso_test-jdk17'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
- task: SonarCloudAnalyze@1
inputs:
jdkversion: 'JAVA_HOME_17_X64'
And these are my logs:
Starting: SonarCloudAnalyze
==============================================================================
Task : Run Code Analysis
Description : Run scanner and upload the results to the SonarCloud server.
Version : 1.43.2
Author : sonarsource
Help : Version: 1.43.2. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
[More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
==============================================================================
/usr/bin/dotnet /home/vsts/work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/1.40.2/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 5.14
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
INFO: Scanner configuration file: /home/vsts/work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/1.40.2/dotnet-sonar-scanner-msbuild/sonar-scanner-4.8.1.3023/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/vsts/work/1/.sonarqube/out/sonar-project.properties
INFO: SonarScanner 4.8.1.3023
INFO: Java 17.0.9 Eclipse Adoptium (64-bit)
INFO: Linux 6.2.0-1016-azure amd64
No, the configuration of the steps is identical to your posting, but in my case, Java 11 is used:
2024-01-26T16:43:32.7643870Z ##[section]Starting: SonarCloudAnalyze
2024-01-26T16:43:32.7652430Z ==============================================================================
2024-01-26T16:43:32.7652809Z Task : Run Code Analysis
2024-01-26T16:43:32.7653004Z Description : Run scanner and upload the results to the SonarCloud server.
2024-01-26T16:43:32.7653278Z Version : 1.43.2
2024-01-26T16:43:32.7653489Z Author : sonarsource
2024-01-26T16:43:32.7653676Z Help : Version: 1.43.2. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
[More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
2024-01-26T16:43:32.7654289Z ==============================================================================
2024-01-26T16:43:33.1025991Z [command]/opt/hostedtoolcache/dotnet/dotnet /myagent/_work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/1.40.2/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
2024-01-26T16:43:33.2203328Z SonarScanner for MSBuild 5.14
2024-01-26T16:43:33.2213159Z Using the .NET Core version of the Scanner for MSBuild
2024-01-26T16:43:33.3168660Z Post-processing started.
2024-01-26T16:43:33.5449131Z Calling the SonarScanner CLI...
2024-01-26T16:43:33.8792149Z INFO: Scanner configuration file: /myagent/_work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/1.40.2/dotnet-sonar-scanner-msbuild/sonar-scanner-4.8.1.3023/conf/sonar-scanner.properties
2024-01-26T16:43:33.8836078Z INFO: Project root configuration file: /myagent/_work/7/.sonarqube/out/sonar-project.properties
2024-01-26T16:43:34.0561579Z INFO: SonarScanner 4.8.1.3023
2024-01-26T16:43:34.0563944Z INFO: Java 11.0.21 Eclipse Adoptium (64-bit)
2024-01-26T16:43:34.0566418Z INFO: Linux 5.15.0-91-generic amd64
2024-01-26T16:43:34.7037991Z INFO: User cache: /home/matt/.sonar/cache
2024-01-26T16:43:35.4071822Z INFO: Analyzing on SonarCloud
2024-01-26T16:43:35.4115322Z INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
2024-01-26T16:43:36.2022574Z INFO: Load global settings
2024-01-26T16:43:36.7402219Z INFO: Load global settings (done) | time=550ms
2024-01-26T16:43:36.7496805Z INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
2024-01-26T16:43:36.7682759Z INFO: User cache: /home/matt/.sonar/cache
2024-01-26T16:43:36.7853316Z INFO: Loading required plugins
2024-01-26T16:43:36.7855234Z INFO: Load plugins index
2024-01-26T16:43:37.2495008Z INFO: Load plugins index (done) | time=463ms
2024-01-26T16:43:37.2517931Z INFO: Load/download plugins
2024-01-26T16:43:37.3356028Z INFO: Load/download plugins (done) | time=86ms
2024-01-26T16:43:38.6647888Z INFO: Found an active CI vendor: 'Azure DevOps'
2024-01-26T16:43:38.7033368Z INFO: Load project settings for component key: 'spydersoft-consulting_techradar-bff'
2024-01-26T16:43:39.1105137Z INFO: Load project settings for component key: 'spydersoft-consulting_techradar-bff' (done) | time=406ms
2024-01-26T16:43:39.1219302Z INFO: Process project properties
2024-01-26T16:43:39.1685157Z INFO: Project key: spydersoft-consulting_techradar-bff
2024-01-26T16:43:39.1688320Z INFO: Base dir: /myagent/_work/7/s/src
2024-01-26T16:43:39.1689744Z INFO: Working dir: /myagent/_work/7/.sonarqube/out/.sonar
2024-01-26T16:43:39.4047886Z INFO: Load project branches
2024-01-26T16:43:39.8254633Z INFO: Load project branches (done) | time=421ms
2024-01-26T16:43:39.8299526Z INFO: Check ALM binding of project 'spydersoft-consulting_techradar-bff'
2024-01-26T16:43:40.2291960Z INFO: Detected project binding: BOUND
2024-01-26T16:43:40.2305167Z INFO: Check ALM binding of project 'spydersoft-consulting_techradar-bff' (done) | time=401ms
2024-01-26T16:43:40.2349771Z INFO: Load project pull requests
2024-01-26T16:43:40.6507156Z INFO: Load project pull requests (done) | time=412ms
2024-01-26T16:43:40.6549308Z INFO: Load branch configuration
2024-01-26T16:43:40.6583864Z INFO: Load branch configuration (done) | time=4ms
2024-01-26T16:43:40.6781111Z INFO: Load quality profiles
2024-01-26T16:43:41.3325461Z INFO: Load quality profiles (done) | time=653ms
2024-01-26T16:43:41.3498236Z INFO: Load active rules
2024-01-26T16:43:52.7640034Z INFO: Load active rules (done) | time=11414ms
2024-01-26T16:43:53.2190761Z INFO: Organization key: spydersoft-mjg
2024-01-26T16:43:53.2210260Z INFO: Branch name: feature/sonar, type: short-lived
2024-01-26T16:43:53.2738730Z INFO: Preprocessing files...
2024-01-26T16:43:53.7054678Z INFO: 7 languages detected in 81 preprocessed files
2024-01-26T16:43:53.7065819Z INFO: 0 files ignored because of inclusion/exclusion patterns
2024-01-26T16:43:53.7069564Z INFO: 96 files ignored because of scm ignore settings
2024-01-26T16:43:53.7818803Z WARN: 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.
2024-01-26T16:43:53.7959941Z INFO: ------------------------------------------------------------------------
2024-01-26T16:43:53.7964976Z INFO: EXECUTION FAILURE
2024-01-26T16:43:53.7968174Z INFO: ------------------------------------------------------------------------
2024-01-26T16:43:53.7975755Z INFO: Total time: 19.987s
2024-01-26T16:43:53.8618390Z INFO: Final Memory: 10M/37M
2024-01-26T16:43:53.8620027Z INFO: ------------------------------------------------------------------------
2024-01-26T16:43:53.8642092Z ##[error]ERROR: Error during SonarScanner execution
2024-01-26T16:43:53.8643687Z ERROR: Error during SonarScanner execution
2024-01-26T16:43:53.8645487Z ##[error]ERROR:
The version of Java (11.0.21) used to run this analysis is deprecated, and SonarCloud no longer supports it. Please upgrade to Java 17 or later.
As a temporary measure, you can set the property 'sonar.scanner.force-deprecated-java-version' to 'true' to continue using Java 11.0.21
This workaround will only be effective until January 28, 2024. After this date, all scans using the deprecated Java 11 will fail.
ERROR:
2024-01-26T16:43:53.8780766Z ERROR:
2024-01-26T16:43:53.8781048Z
2024-01-26T16:43:53.8781911Z The version of Java (11.0.21) used to run this analysis is deprecated, and SonarCloud no longer supports it. Please upgrade to Java 17 or later.
2024-01-26T16:43:53.8783733Z As a temporary measure, you can set the property 'sonar.scanner.force-deprecated-java-version' to 'true' to continue using Java 11.0.21
2024-01-26T16:43:53.8784860Z This workaround will only be effective until January 28, 2024. After this date, all scans using the deprecated Java 11 will fail.
2024-01-26T16:43:53.8785330Z
2024-01-26T16:43:53.8785853Z ERROR:
2024-01-26T16:43:54.2410590Z ##[error]The SonarScanner did not complete successfully
2024-01-26T16:43:54.2412387Z The SonarScanner did not complete successfully
2024-01-26T16:43:54.2413458Z ##[error]16:43:54.24 Post-processing failed. Exit code: 1
2024-01-26T16:43:54.2414781Z 16:43:54.24 Post-processing failed. Exit code: 1
2024-01-26T16:43:54.2586367Z ##[error]The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1
2024-01-26T16:43:54.2642690Z ##[section]Finishing: SonarCloudAnalyze
I am re-provisioning my hosted build agent with the latest runner images, but I still pose the following question: if Sonar no longer supports JDK 11, why is it the default JDK in the runner?
For what it’s worth, I figured this out, and it has to do with the Azure DevOps build agent.
I mistakenly thought that, because the proper ENV variables exist on the build agent, that they are actually available to Azure DevOps as ENV variables. As it turns out, the agent builds it’s own .env file, and for whatever reason, the runner-images provisioning doesn’t seem to pick those up.
I added JAVA_HOME_17_X64 as an environment variable in the .env file for the Azure DevOps agent, and it works.