How to set Branch with Sonar Plugin

Hi

I’m trying to get Sonar up and running with Gradle for our multi-module build.

So far I’ve now managed to get the Sonar build to run, but I’m stuck on how to set the branch with the plugin.

I’ve tried

sonar {
   branch = "MyBranch"
   ...

both in the top level build.gradle and inside the top-level build.gradle’s subprojects and I’ve even tried

project {
   withProjectProperties { props ->
      props["sonar.branch"] = "MyBranch"
      ...

all to no avail. Note that the sonar.branch does show up in the --info output but still no joy once its written out to Sonar.

Edit Apparently sticking the props[“sonar.branch”] statement in the project actually did make “MyBranch” appear against the components under the project. However I still can’t seem to get the branch at the project level.

Anyone got an example that works?

Thanks!

I’m surprised that your first snippet doesn’t work (assuming you’ve added this configuration to the same project that applies the Sonar plugin). Have you tried to use the second snippet for every Gradle project, including the root project?