1
votes

We have a multi-project gradle build, which organizes the projects into directories. Example:

root
+--Libraries
   +-- Project1
   +-- Project2
+--Tools
   +-- Project3
   +-- Project4

Since the SonarRunner plugin is deprecated, we have attempted to use the official SonarQube plugin for gradle. The gradle version used is 2.10.

Due to our project structure, there are problems with the project names: SonarQube plugin receives projects names "Libraries\Project1". "\" is an illegal character for a project name.

Previously, for SonarRunner, the problem was fixed by overriding the ProjectKey property:

// project specific sonar configuration
gradle.projectsEvaluated {
  subprojects {
    sonarRunner {
      sonarProperties {
        def projectKey = "$project.group:$project.name".replaceAll('/', '-')
        property 'sonar.projectKey', projectKey
      }
    }
  }
}

The equivalent tried for SonarQube is

// project specific sonar configuration
gradle.projectsEvaluated {
  subprojects {
    sonarqube{
      properties {
        def projectKey = "$project.group:$project.name".replaceAll('/', '-')
        property 'sonar.projectKey', projectKey
      }
    }
  }
}

However, this doesn't work with SonarQube. Has anyone encountered a similar problem?

Thanks for your help!

1

1 Answers

0
votes

What worked for me, on a Linux environment, was to replace a '/' with ':', and to override the moduleKey. Add this part in your root build.gradle file:

subprojects {

sonarqube {
    String regex = "(.*)/(.*)"
    String projectKey = project.name.replaceAll(regex, "\$1:\$2")
    String sonarModuleKey = rootProject.group + ':' + rootProject.name + ':' + projectKey

    properties {
        property "sonar.moduleKey", sonarModuleKey
    }
}

}