SonarRunner, duplicate projects and projects named 'sonar'

Sonar-Runner, the external tool relies on a the properties file which is generated by Gradle. SonarRunner plugin.

If a multi-project tree contains projects with duplicate names then sonar runner ends up analysing same module twice which ultimately leads to SonarRunner crashing with a “ERROR: Caused by: Can not add the same measure twice on org.sonar.api.resources.Project”

The reason for this is the property key is generated from the which is not necessarily unique. Gradle does not provide any DSL to allow this to be changed, this should not be confused with the SonarRunner property keys “sonar.projectName” or “sonar.projectKey” which are used for different things in the generated properties file.


            String modules = COMMA_JOINER.join(Iterables.transform(enabledChildProjects, new Function<Project, String>() {
                public String apply(Project input) {
                    return input.getName();
            properties.put(convertKey("sonar.modules", projectPrefix), modules);
            for (Project childProject : enabledChildProjects) {
                computeSonarProperties(childProject, properties, sonarPropertiesActionBroadcastMap);

I’ve seen this issue with sonar-runner-dist-2.4, Gradle 2.10 and SonarQube server 5.0.1 and 5.3

Expected outcomes, either

  • SonarRunner plugin to use fully qualified project.path instead of
  • Extra property in sonarRunner { sonarProperties {}} to allow us to chose the custom keys where necessary
  • “Will not fix” - in which case I would expect documentation for SonarRunner plugin to be updated to warn of this issue

Example, in this case

Root project 'multi-project’
±-- Project ‘:base’
| — Project ‘:base:sonarOther’
| ±-- Project ‘:base:sonarOther:bar’
| — Project ‘:base:sonarOther:foo’
— Project ‘:horse’
— Project ‘:horse:base’
— Project ‘:horse:base:baz’

Output grepping on Scan

06:40:25.918 INFO - ------------- Scan bar
06:40:27.674 INFO - ------------- Scan foo
06:40:29.475 INFO - ------------- Scan sonarOther
06:40:29.777 INFO - ------------- Scan base
06:40:30.072 INFO - ------------- Scan bar

As you can see Sonar-Runner goes depth first search, and scans first half of tree, but fails when it gets to the second ‘base’ project, this is because base.sonar.modules can only exist in once …

This can be confirmed by looking at the keys in the generated file


Also, very closely related to this issue is projects named ‘sonar’. I’ve raised this with SonarRunner team –!searchin/sonarqube/squirrel/sonarqube/l20VX71KQ80/HIqJZhE6EAAJ and, The fix here could be the same… If generated file used fully qualified name then this would fix all cases apart from root project being named ‘sonar’…

The ‘sonar-runner’ plugin bundled with Gradle core has been deprecated in favor of the plugin maintained by the sonarqube team. I’d suggest you try that plugin out and see if it solves your problem. The core plugin is effectively EOL and no further maintenance is being done on it.