Sonar and Gradle Multi-Module Projects
Join the DZone community and get the full member experience.
Join For Free$ mvn sonar:sonarA few moments later you should have the metrics available at:
http://localhost:9000/Well, the past few days I was setting up a multi-module Gradle project for Sonar. Let me start by stating that Gradle is awesome. Having the ability to declare dependencies as one-liners and also being able to customize your scripts easily, yet having sensible defaults, is very nice. Kind of the best of both worlds.
Setting up Sonar for a multi module project, though, is unfortunately a bit more complicated, compared to what I am used to in the Maven world. It is not awfully complicated, but it took me a while to collect all the pieces of information.
Getting your Sonar plugin to just doing something is fairly simple. Just follow the basic steps outlined in the plugin documentation at:
One differentiator between the Sonar Plugin for Gradle and Maven is, that the Gradle version does not automatically run code coverage analysis. This needs to be manually setup. This is where the official doc just vaguely refers to Cobertura.
First, I tried using Cobertura for code coverage, but I seemed to run into difficulties for my multi-module projects. The Cobertura Plugin is here:
Some Gradle Sonar Plugin Limitations
The Gradle Sonar Plugin has an annoying limitation, where I can run it for the ROOT project OR for the sub-projects individually. See the following Gradle Jira ticket for details:
Furthermore, I hit the minor issue that I cannot set the links in the Sonar dashboard. This seems to be related to the following Sonar Jira issue:
props["sonar.jacoco.reportPath"] = "${buildDirName}/jacoco.exec"
From http://hillert.blogspot.com/2012/01/sonar-and-gradle-multi-module-projects.html
Opinions expressed by DZone contributors are their own.
Comments