SonarScan for gradle, empty scan results

SonarQube server: Community Edition v10.7
Deployed Via: helm
trying to acheive: Scan a java project with gradle separately from the build script since my project requires JAVA-8 to compile and the sonarqube plugin JAVA-17.
Current behavior: Building with JAVA-8, all of the compiled classes are present, then switching JAVA_HOME to JAVA-17 and running the scan via gradlew sonar -b sonar.gradle.
the second build ends up successful, when going to the sonarqube server it does say that a scan has been performed but it just says “The main branch of this project is empty.”.

I’ll reiterate the steps to reproduce: building the project via a gradle wrapper with JAVA-8 e.g.:

JAVA_HOME={JAVA-8}
gradlew clean build

then:

JAVA_HOME={JAVA-17}
gradlew sonar -b sonar.gradle

the sonar.build contains only:

plugins {
  id "org.sonarqube" version "5.1.0.4882"
}

sonar {
  properties {
    property "sonar.projectKey", "{Project-Key}"
    property "sonar.projectName", "{Project-Name}"
  }
}

thanks in advanced!

Hi,

Welcome to the community!

Could you add the --info flag to the analysis command and post the resulting log, starting from the command itself?

 
Thx,
Ann

Hi, thanks for the reply, I’ve ran the test again with the --info flag as asked, here’s the execution command: ./gradlew sonar -b sonar.gradle -Dsonar.projectKey={Project-key} -Dsonar.projectName={Project-Name} -Dsonar.host.url={Host+Token} --info

here’s the output log:

Initialized native services in: {User}/.gradle/native
The client will now receive all logging from the daemon (pid: 37838). The daemon log file: .gradle/daemon/6.5/daemon-37838.out.log
Starting 3rd build in daemon [uptime: 2 mins 28.969 secs, performance: 100%, non-heap usage: 34% of 268.4 MB]
Using 8 worker leases.
Starting Build
Settings evaluated using settings file '{Project-root-dir}/settings.gradle'.
Settings evaluated using settings file.
Projects loaded. Root project using build file '{Project-root-dir}/sonar.gradle'.
Included projects: [root project 'logparser']

> Configure project :
Evaluating root project 'logparser' using build file '{Project-root-dir}/sonar.gradle'.
All projects evaluated.
Selected primary task 'sonar' from project :
Tasks to be executed: [task ':sonar']
Tasks that were excluded: []
:sonar (Thread[Execution worker for ':',5,main]) started.

> Task :sonar
Caching disabled for task ':sonar' because:
  Build cache is disabled
Task ':sonar' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
User cache: {User}/.sonar/cache
Default locale: "en_IL", source code encoding: "UTF-8" (analysis is platform dependent)
Load global settings
Load global settings (done) | time=900ms
Server id: EA8D9556-AZM6BVE86eG42qy4-67V
Loading required plugins
Load plugins index
Load plugins index (done) | time=159ms
Load/download plugins
Load/download plugins (done) | time=11ms
Process project properties
Process project properties (done) | time=4ms
Project key: {Project-key}
Base dir: {Project-root-dir}
Working dir: {Project-root-dir}/build/sonar
Load project settings for component key: '{Project-key}'
Load project settings for component key: '{Project-key}' (done) | time=147ms
Load quality profiles
Load quality profiles (done) | time=197ms
Load active rules
Load active rules (done) | time=6284ms
Load analysis cache
Load analysis cache (2.0 kB) | time=158ms
Preprocessing files...

0 languages detected in 0 preprocessed files
0 files indexed
0 source files to be analyzed
0/0 source files have been analyzed
0 source files to be analyzed
0/0 source files have been analyzed
CPD Executor CPD calculation finished (done) | time=0ms

> Task :sonar
0 files ignored because of scm ignore settings
Loading plugins for detected languages
Load/download plugins
Load/download plugins (done) | time=1ms
Load project repositories
Load project repositories (done) | time=155ms
Indexing files...
Project configuration:
------------- Run sensors on module logparser
Load metrics repository
Load metrics repository (done) | time=148ms
Sensor JaCoCo XML Report Importer [jacoco]
'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
No report imported, no coverage information will be imported by JaCoCo XML Report Importer
Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1ms
Sensor Java Config Sensor [iac]
Sensor Java Config Sensor [iac] (done) | time=5ms
Sensor IaC Docker Sensor [iac]
Sensor IaC Docker Sensor [iac] (done) | time=24ms
Sensor TextAndSecretsSensor [text]
Available processors: 8
Using 8 threads for analysis.
The property "sonar.tests" is not set. To improve the analysis accuracy, we categorize a file as a test file if any of the following is true:
  * The filename starts with "test"
  * The filename contains "test." or "tests."
  * Any directory in the file path is named: "doc", "docs", "test" or "tests"
  * Any directory in the file path has a name ending in "test" or "tests"

Using git CLI to retrieve untracked files
Analyzing only language associated files, make sure to run the analysis inside a git repository to make use of inclusions specified via "sonar.text.inclusions"
Sensor TextAndSecretsSensor [text] (done) | time=139ms
------------- Run sensors on project
Sensor Zero Coverage Sensor
Sensor Zero Coverage Sensor (done) | time=0ms
CPD Executor Calculating CPD for 0 files
SCM revision ID 'ba51563762aac3c51b7a254dc11dce05b31aa4b8'
Analysis report generated in 24ms, dir size=220.8 kB
Analysis report compressed in 5ms, zip size=20.5 kB
Analysis report uploaded in 297ms
ANALYSIS SUCCESSFUL, you can find the results at: {Project-URL}
Analysis total time: 8.194 s
:sonar (Thread[Execution worker for ':',5,main]) completed. Took 10.493 secs.

BUILD SUCCESSFUL in 10s
1 actionable task: 1 executed

I’ve redacted some data that I don’t think will be important but sensitiv for the troubleshooting, I will say that after the scan is complete the project on the sonarqube server last scan gets updated, so connection to the server seems good.

also if needed the sonar plugin used in the scan is of version 5.1.0.4882.

thanks again.

Hi,

Thanks for the log. We’ve got something weird going on here:

Since you’re using Gradle, the source file should be automatically detected. Can you add -Dsonar.scanner.dumpToFile=[path to file] and post the - redacted as necessary - results?

 
Thx,
Ann

Hi,

I’ve just learned that the parameter has been renamed to -Dsonar.scanner.internal.dumpToFile.

 
Thx,
Ann

Hi Ann, thanks again for the reply.

I’ve ran the same command as I’ve done previously with -Dsonar.scanner.internal.dumpToFile but the dump file stays completely empty, the only output that I’m getting from Gradle is:

> Task :sonar
Analyzing only language associated files, make sure to run the analysis inside a git repository to make use of inclusions specified via "sonar.text.inclusions"

BUILD SUCCESSFUL in 11s
1 actionable task: 1 executed

thanks for the assistance,
Ben.

Hi Ben,

Could you try it the old way, then: sonar.scanner.dumpToFile?

 
Thx,
Ann

Hi, I’ve executed the other command as well but it seems to do even less/nothing then the -Dsonar.scanner.internal.dumpToFile, when running the scan with Dsonar.scanner.internal.dumpToFile its takes a couple of seconds to complete but with the other its pretty much instant, the output of it is just:

> Task :sonar

BUILD SUCCESSFUL in 215ms
1 actionable task: 1 executed

by the way i will say that using the scan while its configured in the main build.gradle works fine and scans are successful, but its a problem with some of my project since they require quite an old version of java to compile.

thanks again!

Hi,

At this point, I suspect there’s some deep Gradle weirdness involved. I’m going to flag this for the folks who know Gradle.

 
Ann

thank Ann for the assistance :raised_hands:!

hey @Ben_Shahar,

Based on the content of the sonar.gradle file you shared, I have a couple of suggestions for you to try.

  1. Include Gradle’s core java plugin in your sonar.gradle plugins section.
    The Gradle scanner relies on the core plugins to recover data about source sets and other language-specific settings.

  2. Use the latest scanner version. (It is unlikely to solve your problem but it should help you benefit from the latest changes)

Let us know if these suggestions solve your problem.

Cheers,

Dorian