9

I have two projects (A and B), which use the same reusable module (C). I upload A into sonarqube without problems, but when I upload B, the sonar-maven-plugin tells me that Module C is already part of project A. How can I fix it? I want both of my projects to be uploaded into sonarqube.

cynepnaxa
  • 1,024
  • 1
  • 14
  • 30

4 Answers4

6
  • If you´re Sonar admin go to http:///background_tasks and select excecution log. You have the following error:
2016.11.18 08:56:08 ERROR [o.s.s.c.t.CeWorkerCallableImpl] Failed to execute task XXXXXX
org.sonar.api.utils.MessageException: Validation of project failed:
  o Module "moduleA" is already part of project "org.company:proj2"
  • So you have to edit the MODULE pom.xml in your project proj1, and say it to Sonar that this module will be named as:
<properties>
    <sonar.moduleKey>org.company:proj2:moduleA-NEW</sonar.moduleKey>
</properties>
Matias Burni
  • 509
  • 6
  • 11
  • This answer actually will solve it for most. Along with the comment by Somaiah Kumbera, our problem was that our key was not unique because the group id was incorrect, we had it working on branches but :master would not because of a lax project somewhere else using a global groupId. The correct answer here should be to make sure that the combination of groupId:artifactId and is unique. Excluding modules from analysis is not necessarily the correct thing to do. – krystan honour Mar 05 '18 at 15:05
4

I just had this problem as well. If you are running a newer version of Maven, you can exclude modules. This may or may not be a sufficient answer for you, but it was for me.

When you run Sonar on project A, run it normally (no --projects switch). When you run Sonar on project B, supply an exclusion list (with the --projects switch).

For Project A:

mvn sonar:sonar

then

mvn sonar:sonar --projects !moduleC

This method is mentioned briefly here:

http://docs.sonarqube.org/display/SONAR/Analyzing+with+Maven#AnalyzingwithMaven-ExcludingamodulefromSonarQubeanalysis

schnatterer
  • 7,525
  • 7
  • 61
  • 80
mpderbec
  • 354
  • 3
  • 7
  • Thanks for your reply! I think problem can be solved in three different ways: – cynepnaxa Sep 29 '14 at 04:05
  • 1) Disable check in sonar. 2) Exclude module from analysis. 3) Copy-paste and rename module. We already apply 3rd ways. But your approach(2) is better, because (3) is worstest. But anyway best approach i think is (1). I don't understand at all what for this check? For example i have two projects with same module, i want to see all content analysis of both my projects. Who needs analyse only part of project? – cynepnaxa Sep 29 '14 at 04:13
  • 2
    How do you disable the check in sonar? – Glenn Bech Dec 18 '14 at 08:08
4

The sonar module name is created from maven's

<maven groupId>:<maven artifactId>:<branch name>

In some cases, different applications may have the same values for these.

In this case sonar will get confused, and rightly so.

The solution in this case is to use Matias Burni's solution with

<properties>
    <sonar.moduleKey>groupId:artifactId:some distinct identifier</sonar.moduleKey>
</properties>

However the more correct way to do this would be to have distinct groupId -artifactId combinations for different applications.

Somaiah Kumbera
  • 7,063
  • 4
  • 43
  • 44
-1

I found another way to exclude module from analysis. We use it, works fine. It's very simple.

  1. New project can't be created automatically because of module duplication. So create it manualy. Log into web interface as admin. Then use Settings -> Provisioning -> Create.
  2. Open created project. Then Configuration -> Settings -> Exclusions -> Files -> Module Exclusions.
cynepnaxa
  • 1,024
  • 1
  • 14
  • 30
  • Yes, this options exists, but even disabling the module from the UI if you try to submit two modules with the same name, you will get the failure on the Sonar execution. So, the option you propose is valid if you want to exclude a module which is not repeated. – Matias Burni Dec 18 '16 at 12:30