Sonarqube Reporting in a Multi-Module Android Project
Pain-Free Sonarqube Setup
Hey there! 👋 I might now your pain; there are plenty of good examples out there when it comes to Sonarqube for single module apps but not that many when it comes to multi-modules. This post describes swiftly a very common use case, check the Goal section to see if it matches the use case you are trying to achieve.
Goal
Centralise Jacoco coverage results & Detekt results of each sub-module in a single Sonarqube project.
Setup
To centralise the results the key is to have a single Sonarqube instance, this instance needs to be declared in the project_root/build.gradle
:
Tip: To keep the root build.gradle
clean you can place the Sonarqube related code in a separate sonar.gradle
file.
The solution lies in the lines 23–26 and 27–30, have a closer look, through these lines we tell Sonarqube which Jacoco and Detekt reports to publish.
At this point the Sonarqube setup is complete, make sure that Jacoco and Detekt are properly setup in each sub-module build.gradle
and properly generate the respective XML reports. If that’s working, you are ready to publish to Sonarqube.
Publish to Sonarqube
Run Detekt and Jacoco Gradle tasks, once they finish, make sure the XML reports are correctly generated in the build/reports
folder of each module.
If the reports are present, run .gradlew sonarqube
and you are done. Check the result in the Sonarqube web platform.
I hope you found it helpful, if you have any questions and feedback please let me know via the comments section.
Stay positive & healthy; see you on the next one!