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'
}
}

Due to other tool limitations (to name the Bitbucket Sonar Plugin) we need all projects in the composite to contribute to the same Sonar project.
As far as I can see that’s currently not possible.

does this actually work ?

Thank you for documenting your solution, @Justin_Doran :+1:

I myself also would like (same as @lkoe ) to be able to report all parts of the composite to one sonarqube-project … and by searching for a solution i arrived here :wave:

Have you all given up by now? :clown_face: :cry:

I tried to configure the sonarqube task in the composite-build-parent and to list all the relative src-dirs under sonar.sources … but that did not work

Can i maybe put a list of source-folders into the property like this?

Oh, i am a bit sorry to ask, but … @JackSAIC could you maybe flesh out your solution a
tiny bit? (the strategically located things, thats what i probably am most curious about :nerd_face: )

Hello @daniel … this is your future self spea…err … writing :wave:

While tackling a problem i just found your … i mean … my posting here … i must tell you, nothing has happened here so far. I currently still search for a solution to include “subprojects” that are included via includeBuild in the settings.gradle

But … wait … maybe something did happen and i just found my own stuff before finding more actionable results :thinking: … i will keep you informed, former self, if i find something! TallyHO! Onwards, Horses! Lets find us some solutions!! :cowboy_hat_face: :horse_racing: