SonarQube Scanner for Gradle is not using sonar.projectKey set for rootProject into Subprojects

(Chris L) #1

we have the exact same problem as the following, anyone know how to resolve this?

(James Justinic) #2

This sounds like it is working as designed, but there is an incorrect expectation on what happens with the sonar.projectKey property. Setting the sonar.projectKey on the root project would cause it to be inherited by subprojects, but a different key is used for subprojects (modules to sonar). A multi-project build in Gradle maps to a single project with many modules in sonar:

(Root Project) - sonar.projectKey
  |- (Subproject 1) - sonar.moduleKey
  |- (Subproject 2) - sonar.moduleKey
  |- (Subproject 3) - sonar.moduleKey

The default projectKey and the default moduleKey on each subproject are generated independently, so if you need to customize sonar.projectKey, you probably want to customize sonar.moduleKey for all subprojects as well. You can use the subprojects {...} block to do this near your existing configuration of sonar.projectKey, if desired.

(Chris L) #3

Great!. It works. Appreciate the help, James.

BTW, should Sonar document mentioned this hidden treasure property “moduleKey”. I assume that you got that by digging into their source code?


(James Justinic) #4

In our case, the root project has an invalid character, so we received an error for each project that read:

... is not a valid project or module key

When setting sonar.projectKey only resolved the root project, it seemed logical enough to try sonar.moduleKey based on this specific error message.

I did search for “moduleKey” in the github repository out of curiosity though because I was also surprised with it being virtually unmentioned in the actual documentation.