Sonarqube Gradle plugin and Composite Builds

Sonar Gradle Plugin 2.8
SonarQube 6.7.6 (Community Edition)
Sonar Scanner 4.2
Gradle 5.3.1

I’ve been working on trying to get the sonarqube gradle task to scan our gradle project that is structured as a “composite” build using the “includeBuild” statements at the top level build (settings.gradle). We had to go to composite build to support our project which is basically a group of multi-project gradle builds that we release at the same time. What I’m seeing is that the sonarqube task cannot see anything included in the build through the “includeBuild” feature for creating composite builds, so I’m unable to scan the entire project tree in one go. If I create a sonarscan task that calls the other builds sonarqube task, I only receive one scan in the server because each build overwrites the previous builds sonar scan resuls, so the last one to run is what is visible on the server.

What does work is running a pure command-line scan with sonar-scanner and sonar-project.properties strategically located throughout the project so that I can scan eveything in one shot. So, I at least know that this is possible. We would like it to work correctly through gradle, so we don’t have to maintain a separate program install for the scanner and allow the gradle plugin to maintain our scanner version and blend in with our toolchain.

Is what I’m trying to do possible with the sonarqube gradle plugin?

I am interested in this too

Is there perhaps a way to publish the sonar scan results for the included builds in an iterative manner, without the single builds overwriting the sonar project?

I was able to work through this issue by creating a unique task in the composite build.gradle. Then in each module declaring a unique project name property

Project domain structure

project-domain
|-> project-composite
|   |->build.gradle
|-> project-mod1
|   |->build.gradle
|-> project-mod2
|   |->build.gradle

project-composite build.gradle snippit

task sonarqubeMod1 {
dependsOn gradle.includedBuild('mod1').task(':sonarqube')
}

task sonarqubeMod2 {
dependsOn gradle.includedBuild('mod2').task(':sonarqube')
}

project-mod1 build.gradle snippit

sonarqube {
properties {
    property 'sonar.projectName', 'mod1'
    property 'sonar.sources', 'src/main'
    property 'sonar.sourceEncoding', 'UTF-8'
    property 'sonar.language', 'java'
}
}

project-mod2 build.gradle snippit

sonarqube {
properties {
    property 'sonar.projectName', 'mod2'
    property 'sonar.sources', 'src/main'
    property 'sonar.sourceEncoding', 'UTF-8'
    property 'sonar.language', 'java'
}
}
1 Like