Sonar maven plugin: same project key for all modules does not work?

There must be a way to uniquely identify each component. As Steve C said, you can't have two projects with the same project key. And within a project, modules must also have unique identifiers. Otherwise, analysis of the second "module b" would overwrite the first "module b".


Since SonarQube 7.6

Modules have been removed in a recent release. I couldn't yet validate if the below, modules-based solution works on SonarQube 8.x, but assume a different solution has to be used. When I contacted SonarQube support they suggested to manage permissions on project key prefixes, and use prefix-scoped project creation permissions to dynamically create project keys sharing that prefix.

In this case your pom.xml would look like this:

<properties>
    <sonar.projectKey>
        YourKey-${project.groupId}:${project.artifactId}
    </sonar.projectKey>
</properties>

where YourKey is the project-prefix. This requires your SonarQube admin to apply the suggested permission scheme.

Pre SonarQube 7.6

SonarQube prior to 7.6 is/was module-aware. To define modules in your parent.pom, you declare the following properties:

<properties>
    <sonar.projectKey>
        YourKey
    </sonar.projectKey>
    <sonar.moduleKey>
        ${project.groupId}:${project.artifactId}
    </sonar.moduleKey>
</properties>

Both properties will be inherited by your modules. This will then compile the result into a single Sonar report, tracking the sub-modules under the common projectKey. Interestingly the result is:

[INFO] Reactor Summary:
[INFO] 
[INFO] parent ................................. SUCCESS [01:14 min]
[INFO] module1................................. SKIPPED
[INFO] module2 ................................ SKIPPED
[INFO] module3 ................................ SKIPPED

I'm therefore not sure, how the exact module resolution was done, but in the end all modules showed up in the report.


According to SonarQube Analysis Parameters:

sonar.projectKey

The project key that is unique for each project. Allowed characters are: letters, numbers, '-', '_', '.' and ':', with at least one non-digit.
When using Maven, it is automatically set to <groupId>:<artifactId>.

Therefore, remove your sonar.projectKey configuration and it should work.

(I have been through the same loop).