Sonar-scanner CLI does not find issues found by sonar gradle plugin

Version information:

  • which versions are you using:
    SQ Community Edition Version 8.9.9 (build 56886)
    Sonar-Scanner CLI:
    -Java Eclipse Adoptium (64-bit)
    -Mac OS X 12.6 x86_64

  • how is SonarQube deployed: zip

  • what are you trying to achieve: obtain findings parity between CLI scanner and gradle-plugin scanner

  • what have you tried so far to achieve this:

  1. created sample gradle/java project with issues not found while using CLI (java:S1948)
  2. configured project for gradle-plugin scanning (build.gradle configurations) and CLI scanning (
  3. created scanning scripts for both scenarios for “one-click” run
  4. put the whole project on github at GitHub - AndreiRinea/sq-diff-scan

I’ve compared log files of the CLI scan run ( sq-diff-scan/sq-scan-via-cli.log at master · AndreiRinea/sq-diff-scan · GitHub ) and the Gradle scan run ( sq-diff-scan/sq-scan-via-gradle.log at master · AndreiRinea/sq-diff-scan · GitHub ) but can’t find any relevant missing configuration for CLI as compared to the (successful) gradle run…

Would I be able to run the CLI scanner to obtain the same level of thoroughness as the gradle scanner? I would need a unified approach on a large project portfolio spanning across many stacks and would hate to make a different scenario for each (gradle, maven, npm etc.)

I did read as much as I could on the community but aside from When to use sonar-scanner CLI versus SonarScanner plugin available with build tool’s like Maven,Gradle. etctera..? - #2 by bcipollone I haven’t found much information.


Using the specialized scanners is easier because they set many additional properties automatically. Look at the SonarScanner for Gradle, for example:

Notice that additional defaults are provided for projects that have the Java-base or Java plugin applied:

Property Gradle default
sonar.sourceEncoding ${project.compileJava.options.encoding} ${project.targetCompatibility} ${project.targetCompatibility}
sonar.sources ${sourceSets.main.allJava.srcDirs} (filtered to only include existing directories)
sonar.tests ${sourceSets.test.allJava.srcDirs} (filtered to only include existing directories) ${sourceSets.main.output.classesDir} ${sourceSets.main.compileClasspath} (filtering to only include files; rt.jar and jfxrt.jar added if necessary) ${sourceSets.test.output.classesDir} ${sourceSets.test.compileClasspath} (filtering to only include files; rt.jar and jfxrt.jar added if necessary)
sonar.junit.reportPaths ${test.testResultsDir} (if the directory exists)

If you’re using the SonarScanner CLI you’ll need to set all properties manually (see also the section “Java analysis and bytecode” on Java).

1 Like

Is there a way to list out all the properties and their values that the gradle plugin runs?

I already have set the following ones for CLI:

  • sonar.sources
  • sonar.tests

(these can be observed at sq-diff-scan/ at master · AndreiRinea/sq-diff-scan · GitHub )

additionally I’ve followed the debug-verbose log of the gradle scan and also set:


I’ve seen the CLI run getting (correctly) resolved:

  • (based on jdkHome)

I added (same value as, 1.8) as we “speak”, ( trying also on CLI · AndreiRinea/sq-diff-scan@02c6dfa · GitHub ) but no improvement.