Project 'quarkusio_quarkus' can't have 2 modules with the following key: quarkusio_quarkus

Hi,

I’m trying to set up Sonarcloud for the Quarkus project and things are not working very well:

Error: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project quarkus-parent: Project ‘quarkusio_quarkus’ can’t have 2 modules with the following key: quarkusio_quarkus -> [Help 1]

Setup is the following:

I only build the master tree for now.

The project is a very large multi-modules Maven project but I don’t really know what the problem could be given the error message.

I saw a few persons reporting the same issues but I couldn’t find anything helpful.

I followed the instructions given on Sonarcloud, except I don’t run the tests for now (I know I won’t have test coverage but that’s a good first step).

Thanks!

I found this: https://stackoverflow.com/questions/43627759/sonar-maven-plugin-same-project-key-for-all-modules-does-not-work .

But as of 8, it says I should override the projectKey which I’m not sure I can on Sonarcloud?

I got a bit further by removing the sonar.projectKey property from my POM file. I have no idea if it’s the right fix (setting it is part of the instructions of Sonarcloud when creating a new project).

Then I get a new error:

Error: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project quarkus-parent: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property. -> [Help 1]

which is not very helpful either.

I certainly expect my Java project to contain .java files and there’s no listing of the problematic files so… :).

Welcome to the community and sorry for the delayed response!

SonarCloud’s documentation for Maven does recommend setting the project key, by setting <sonar.projectKey>my_project</sonar.projectKey> in the <properties>...</properties> section of your parent pom.xml.

… Unfortunately the documentation seems to miss the case of multi-module Maven projects, where simply doing this will result in the failure you experienced. In a multi-module Maven project, the modules will inherit this setting, they try to use the same sonar.projectKey value as their key, and this will not work.

One option is to set the project key like this in pom.xml:

<sonar.projectKey>quarkusio_quarkus</sonar.projectKey>
<sonar.moduleKey>${artifactId}</sonar.moduleKey>

This way, the modules will use ${artifactId} as their key, which is dynamically resolved, so they will have their proper unique keys.

Another way is to set the project key by passing a parameter to the scanner:

mvn ... -Dsonar.projectKey=quarkusio_quarkus

This happens when the scanner cannot find the compiled .class files, which often happens if you forgot to do a mvn compile (or equivalent) before mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar. Give that a try, it should work!