Grouping gradle projects for analysis on sonarqube

Sonar Server : v2025.2
Sonar gradle plugin : 6.1.0.5360
scanner-java-library: 3.3.1.450

Hi there,

I have the following gradle project monorepo setup

my-gradle-monorepo/
├── build.gradle.kts
├── settings.gradle.kts
├── gradle/
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── apps/
│   ├── app1/
│   │   └── build.gradle.kts
│   └── app2/
│       └── build.gradle.kts
├── libraries/
│   ├── lib1/
│   │   └── build.gradle.kts
│   ├── lib2/
│   │   └── build.gradle.kts
│   ├── lib3/
│   │   └── build.gradle.kts
│   └── lib4/
│       └── build.gradle.kts
├── shared/
│   ├── utils/
│   │   └── build.gradle.kts
│   ├── common/
│   │   └── build.gradle.kts
│   └── network/
│       └── build.gradle.kts
└── README.md

This is a gradle monorepo where I would want to club multiple modules together as a single sonar
project. For example a separate

  1. my-gradle-monorepo-libraries : Containing all the modules under the libraries folder
  2. my-gradle-monorepo-apps: Containing all the modules under the apps folder
  3. my-gradle-monorepo-shared : Containing all the modules under the shared folder

Is there a way for me achieve this using the sonar gradle plugin? In it’s current implementation since the sonar plugin can only be applied to the root project, it would treat the my-gradle-monorepo as a single project with all the subprojects as a part of it.

Hi,

I’m guessing that each app (app1, app2, &etc) is a separate build? If so, it looks like you’re interested in Analyzing multi-project builds.

 
HTH,
Ann

Hi Ann,
Those are not separate builds. They are all a part of the same gradle project.
This is a gradle multi-project build .
However from the POV of sonar, I want to list this as 3 projects as mentioned above.

Hi,

You initially called it a “monorepo” which to took to mean “multiple, independently built projects that live in the same repo”.

Generally it’s 1 build = 1 project.

If they all build together then you’ve got a little juggling to do (and TBH if they’re interdependent, then I’m not sure how well this is going to work).

The docs on analyzing multi-project builds tell you to apply the SonarQube plugin to the root project. Here I suppose you’ll do that for each sub-project. Make sure you give each one a unique sonar.projectKey value. And then run analysis 3 times, once for each project.

 
HTH,
Ann

Hi Ann,

Thanks that helps. That’s our current setup too where we modify the sonarqube extension at configuration time and run the build multiple times.