SonarScanner for Azure DevOps Not working with Gradle

Current Settings and Output : Analysis data is not reflecting

I did not configure any code in the project or app Gradle file, I have configured the solar cloud in the pipeline using the classic editor as mentioned in the doc.

Should I configure the sonar in Project or app Gradle file Android source code?

How to enable the sonar lint in the pipeline?

Analyzing a Java project with Maven or Gradle

  1. In your build definition, add:
  • At least Prepare Analysis Configuration task
  • Optionally Publish Quality Gate Result task
  1. Reorder the tasks to respect the following order:
  • Prepare Analysis Configuration task before the Maven or Gradle task.
  • Publish Quality Gate Result task after the Maven or Gradle task.
  1. Click on the Prepare Analysis Configuration task to configure it:
  • Select the SonarQube Server
  • Select Integrate with Maven or Gradle
  1. On the Maven or Gradle task, in Code Analysis , check Run SonarQube or SonarCloud Analysis

Once all this is done, you can trigger a build.

Hi @Maheswaran_Mohan,

The Gradle task for Azure DevOps currently support only Gradle 3.x and below for full functionality (coverage and build)

Since Gradle 4, some breaking changes have been introduced, and the Gradle task were not updated for that. I Created a first pull request a few months ago to make the build green again, an another one is in progress to bring back the coverage as well (in fast the class directories configuration field was hard-coded and target old Gradle 3.x paths).

If you have access to the build agent binaries, then you can hack a bit the task, in the mean time there’s not that much workaround possible.

Mickaël

It dos’t make any sense to me.

I am using following version in the project.

classpath ‘com.android.tools.build:gradle:3.5.3’

My Question is why Analysis data is not reflecting in Sonar cloud dashboard? all the metrics are showing as zero?

Ok, my bad.

So then, do you have a successful analysis in the Run Code Analysis task ?

Do you have any kind of warning in the top right corner of your project’s homepage on SonarCloud ?

Thanks.

Yes, I have a successful analysis in the code Analysis task.

it doesn’t show any warning…

Version details in my project or source code:

Plugin version:
classpath ‘com.android.tools.build:gradle:3.5.3

Gradle version
distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip

Ah, so you have Gradle 5 ? Coverage doesn’t work with this version.

Are you sure that you have codesmell in your code ? Can you just add a //TODO somewhere to see if it pops ?

Will it work if i downgrade the Gradle version to 3.x Sure?

yes i have codesmell in the code … Following is the analysis result by android studio inbuilt tool (lint)

Can you share the log in debug mode of the gradle build task ? So just i can have a look of what it does before doing anything.

Thanks !

I could see following output in the log:

image

##[section]Starting: gradlew build

==============================================================================

Task : Gradle

Description : Build using a Gradle wrapper script

Version : 2.158.0

Author : Microsoft Corporation

Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/gradle

==============================================================================

SonarQube analysis is enabled.

Checkstyle analysis is enabled.

FindBugs analysis is enabled.

PMD analysis is enabled.

SYSTEMVSSCONNECTION exists true

[command]C:\windows\system32\cmd.exe /D /S /C “D:\a\1\s\gradlew.bat build -I D:\a_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.158.0\node_modules\codeanalysis-common\sonar.gradle sonarqube -I D:\a_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.158.0\node_modules\codeanalysis-common\checkstyle.gradle -I D:\a_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.158.0\node_modules\codeanalysis-common\findbugs.gradle -I D:\a_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.158.0\node_modules\codeanalysis-common\pmd.gradle”

Downloading https://services.gradle.org/distributions/gradle-5.4.1-all.zip

Unzipping C:\Users\VssAdministrator.gradle\wrapper\dists\gradle-5.4.1-all\3221gyojl5jsh0helicew7rwx\gradle-5.4.1-all.zip to C:\Users\VssAdministrator.gradle\wrapper\dists\gradle-5.4.1-all\3221gyojl5jsh0helicew7rwx

Welcome to Gradle 5.4.1!

Here are the highlights of this release:

  • Run builds with JDK12

  • New API for Incremental Tasks

  • Updates to native projects, including Swift 5 support

For more details see Gradle 5.4.1 Release Notes

Starting a Gradle Daemon (subsequent builds will be faster)

Configure project :

Applying the Checkstyle plugin to project CodingWithMitch

Applying the FindBugs plugin to project CodingWithMitch

Applying the PMD plugin to all projects

Configure project :app

Applying the Checkstyle plugin to project app

Applying the FindBugs plugin to project app

Applying the PMD plugin to all projects

app: ‘annotationProcessor’ dependencies won’t be recognized as kapt annotation processors. Please change the configuration name to ‘kapt’ for these artifacts: ‘com.github.bumptech.glide:compiler:4.9.0’.

Task :app:preBuild UP-TO-DATE

Task :app:preDebugBuild UP-TO-DATE

Task :app:compileDebugAidl NO-SOURCE

Task :app:compileDebugRenderscript NO-SOURCE

Task :app:checkDebugManifest

Task :app:generateDebugBuildConfig

Task :app:writeDebugApplicationId

Task :app:generateSafeArgsDebug

Task :app:mainApkListPersistenceDebug

Task :app:generateDebugResValues

Task :app:generateDebugResources

Task :app:createDebugCompatibleScreenManifests

Task :app:processDebugManifest

Task :app:mergeDebugShaders

Task :app:compileDebugShaders

Task :app:generateDebugAssets

Task :app:mergeDebugAssets

Task :app:processDebugJavaRes NO-SOURCE

Task :app:mergeDebugResources

Task :app:processDebugResources

Task :app:kaptGenerateStubsDebugKotlin

Task :app:kaptDebugKotlin

w: warning: The following options were not recognized by any processor: ‘[kapt.kotlin.generated, room.incremental]’

Task :app:compileDebugKotlin

w: D:\a\1\s\app\src\main\java\com\codingwithmitch\openapi\repository\NetworkBoundResource.kt: (154, 6): This class can only be used with the compiler argument ‘-Xuse-experimental=kotlin.Experimental’

Task :app:javaPreCompileDebug

Task :app:compileDebugJavaWithJavac

Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: D:\a\1\s\app\build\generated\source\kapt\debug\com\codingwithmitch\openapi\di\DaggerAppComponent.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

Task :app:compileDebugSources

Task :app:mergeDebugJavaResource

Task :app:checkDebugDuplicateClasses

Task :app:desugarDebugFileDependencies

Task :app:mergeLibDexDebug

Task :app:transformClassesWithDexBuilderForDebug

Task :app:mergeExtDexDebug

Task :app:validateSigningDebug

Task :app:signingConfigWriterDebug

Task :app:mergeProjectDexDebug

Task :app:mergeDebugJniLibFolders

Task :app:preReleaseBuild UP-TO-DATE

Task :app:compileReleaseAidl NO-SOURCE

Task :app:compileReleaseRenderscript NO-SOURCE

Task :app:checkReleaseManifest

Task :app:generateReleaseBuildConfig

Task :app:writeReleaseApplicationId

Task :app:generateSafeArgsRelease

Task :app:mainApkListPersistenceRelease

Task :app:generateReleaseResValues

Task :app:generateReleaseResources

Task :app:mergeDebugNativeLibs

Task :app:stripDebugDebugSymbols

Task :app:packageDebug

Task :app:assembleDebug

Task :app:createReleaseCompatibleScreenManifests

Task :app:processReleaseManifest

Task :app:prepareLintJar

Task :app:checkReleaseDuplicateClasses

Task :app:mergeReleaseResources

Task :app:processReleaseResources

Task :app:kaptGenerateStubsReleaseKotlin

Task :app:kaptReleaseKotlin

w: warning: The following options were not recognized by any processor: ‘[kapt.kotlin.generated, room.incremental]’

Task :app:compileReleaseKotlin

w: D:\a\1\s\app\src\main\java\com\codingwithmitch\openapi\repository\NetworkBoundResource.kt: (154, 6): This class can only be used with the compiler argument ‘-Xuse-experimental=kotlin.Experimental’

Task :app:javaPreCompileRelease

Task :app:compileReleaseJavaWithJavac

Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: D:\a\1\s\app\build\generated\source\kapt\release\com\codingwithmitch\openapi\di\DaggerAppComponent.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

Task :app:compileReleaseSources

Task :app:lintVitalRelease SKIPPED

Task :app:desugarReleaseFileDependencies

Task :app:transformClassesWithDexBuilderForRelease

Task :app:mergeReleaseShaders

Task :app:compileReleaseShaders

Task :app:generateReleaseAssets

Task :app:mergeReleaseAssets

Task :app:processReleaseJavaRes NO-SOURCE

Task :app:mergeExtDexRelease

Task :app:mergeReleaseJavaResource

Task :app:signingConfigWriterRelease

Task :app:mergeReleaseJniLibFolders

Task :app:mergeDexRelease

Task :app:lint

Calling mockable JAR artifact transform to create file: C:\Users\VssAdministrator.gradle\caches\transforms-2\files-2.1\1048f609faee100104fcbbcd25c6d13c\android.jar with input C:\Program Files (x86)\Android\android-sdk\platforms\android-28\android.jar

Task :app:mergeReleaseNativeLibs

Task :app:lint

Ran lint on variant debug: 114 issues found

Ran lint on variant release: 114 issues found

Wrote HTML report to file:///D:/a/1/s/app/build/reports/lint-results.html

Wrote XML report to file:///D:/a/1/s/app/build/reports/lint-results.xml

Task :app:stripReleaseDebugSymbols

Task :app:packageRelease

Task :app:assembleRelease

Task :app:assemble

Task :app:preDebugUnitTestBuild UP-TO-DATE

Task :app:processDebugUnitTestJavaRes NO-SOURCE

Task :app:preReleaseUnitTestBuild UP-TO-DATE

Task :app:processReleaseUnitTestJavaRes NO-SOURCE

Task :app:kaptGenerateStubsDebugUnitTestKotlin

Task :app:kaptDebugUnitTestKotlin

Task :app:compileDebugUnitTestKotlin

Task :app:kaptGenerateStubsReleaseUnitTestKotlin

Task :app:kaptReleaseUnitTestKotlin

Task :app:compileReleaseUnitTestKotlin

Task :app:javaPreCompileDebugUnitTest

Task :app:compileDebugUnitTestJavaWithJavac NO-SOURCE

Task :app:testDebugUnitTest

Task :app:javaPreCompileReleaseUnitTest

Task :app:compileReleaseUnitTestJavaWithJavac NO-SOURCE

Task :app:testReleaseUnitTest

Task :app:test

Task :app:check

Task :app:build

Task :app:bundleDebugClasses

Task :app:preDebugAndroidTestBuild SKIPPED

Task :app:compileDebugAndroidTestAidl NO-SOURCE

Task :app:processDebugAndroidTestManifest

Task :app:compileDebugAndroidTestRenderscript NO-SOURCE

Task :app:generateDebugAndroidTestBuildConfig

Task :app:mainApkListPersistenceDebugAndroidTest

Task :app:generateDebugAndroidTestResValues

Task :app:generateDebugAndroidTestResources

Task :app:mergeDebugAndroidTestResources

Task :app:processDebugAndroidTestResources

Task :app:kaptGenerateStubsDebugAndroidTestKotlin

Task :app:kaptDebugAndroidTestKotlin

Task :app:compileDebugAndroidTestKotlin

w: D:\a\1\s\app\src\androidTest\java\com\codingwithmitch\openapi\ExampleInstrumentedTest.kt: (3, 22): ‘InstrumentationRegistry’ is deprecated. Deprecated in Java

w: D:\a\1\s\app\src\androidTest\java\com\codingwithmitch\openapi\ExampleInstrumentedTest.kt: (4, 29): ‘AndroidJUnit4’ is deprecated. Deprecated in Java

w: D:\a\1\s\app\src\androidTest\java\com\codingwithmitch\openapi\ExampleInstrumentedTest.kt: (16, 10): ‘AndroidJUnit4’ is deprecated. Deprecated in Java

w: D:\a\1\s\app\src\androidTest\java\com\codingwithmitch\openapi\ExampleInstrumentedTest.kt: (21, 26): ‘InstrumentationRegistry’ is deprecated. Deprecated in Java

w: D:\a\1\s\app\src\androidTest\java\com\codingwithmitch\openapi\ExampleInstrumentedTest.kt: (21, 50): ‘getTargetContext(): Context!’ is deprecated. Deprecated in Java

Task :app:javaPreCompileDebugAndroidTest

Task :app:compileDebugAndroidTestJavaWithJavac

Task :sonarqube

WARNING: API ‘variant.getJavaCompile()’ is obsolete and has been replaced with ‘variant.getJavaCompileProvider()’.

It will be removed at the end of 2019.

For more information, see Task Configuration Avoidance.

To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.

Use ‘–warning-mode all’ to show the individual deprecation warnings.

See Command-Line Interface

BUILD SUCCESSFUL in 11m 2s

85 actionable tasks: 85 executed

Only single test suite found, parsing its information.

Only single test suite found, parsing its information.

##[section]Async Command Start: Publish test results

Publishing test results to test run ‘46’.

TestResults To Publish 1, Test run id:46

Publishing test results to test run ‘46’.

TestResults To Publish 1, Test run id:46

Test results publishing 1, remaining: 0. Test run id: 46

Test results publishing 1, remaining: 0. Test run id: 46

Published Test Run : https://dev.azure.com/maheswaranecemohan/maheswaranecemohan/_TestManagement/Runs?runId=46&_a=runCharts.

##[section]Async Command End: Publish test results

##[section]Finishing: gradlew build