Change sonar.modules property to add more projects manually


(x1000) #1

I have a bunch of non-gradle sonar modules that I would like to add to the analysis (so that they show up in one run).

Is there an easy way to add something to sonar.modules after gradle has created its own list but before the runner is executed ?

// SonarRunner.groovy
    void run() {
        def properties = getSonarProperties()
        // add more modules to "sonar.modules" ?
        def runner = Runner.create(properties)
        runner.execute()
    }

(Peter Niederwieser) #2

You should be able to configure ‘sonarRunner.sonarProperties’ in ‘gradle.projectsEvaluated’ or ‘sonarRunner.doFirst’. These are the exact Sonar properties that will be passed to Sonar. Note that you’ll have to use this syntax: ‘sonarRunner.sonarProperties += [one: “foo”, two: “bar”]’.


(x1000) #3

Thanks, but I can’t get this to work.

I can only supply a config action as sonarRunner { sonarProperties { property … } } but the code like

gradle.projectsEvaluated {
    sonarRunner.sonarProperties += [one: "foo", two: "bar"]
 }

results in

Could not find property ‘sonarProperties’ on org.gradle.api.sonar.runner.SonarRunnerExtension_Decorated@34dce871.


(Peter Niederwieser) #4

It has to be ‘tasks.sonarRunner.sonarProperties’. Make sure to do this in the same project where you apply the ‘sonar-runner’ plugin.


(x1000) #5

Thanks, that did the trick:

gradle.projectsEvaluated {
      def newModules = tasks.sonarRunner.sonarProperties["sonar.modules"] + ",testmod"
      tasks.sonarRunner.sonarProperties += [ "sonar.modules" : newModules]
}