SonarQube: Validation of project failed, Module is already part of project - sonarqube

I am trying to analyze one Maven project (with the SonarQube Scanner for Maven) and I am getting the following validation error: Module "com.company:module1" is already part of project "com.company".
I would like to ask you if there is a way to turn this validation off or what should I do in order to analyze the project the second project without deleting the first one.

There's no way to turn this validation off; component keys must be unique across the instance. To be able to analyze both projects, you must remove (or exclude) the module from one of the projects. If the already-analyzed project is the one that loses the module, make your configuration changes, re-analyze, and then you should be able to analyze the second project.

Related

sonar and maven multi-module project - can sonar analyze every module separately?

I have a multi-module project, and O want sonar to analyze each project by himself. For example, to check duplicated lines only in the same module and not compere to all the project code?
If you want them to be separate from SonarQube's point of view, then you have to scan them separately. SonarQube will not be "creating a different project in the same repo". It doesn't care what the source location is for each project.
So, in your build process that runs the scans, you'll simply have to "cd" into each submodule directory and run "sonar:sonar" (or use the sonar-scanner), specifying the module name for each. You'll need to ensure that the module name is a unique SonarQube project.

How to update only one module in multi module project

I have a multi module project in which each module is written in different languages. I have added this project as a multi module project in local sonar instance according to the sonar documentation in which each sub module having separate sonar-project.properties file.
Anyway I wanted to analyse only one module because other modules doesn't have any changes. For that I have to add the project key to the sonar.project-properties file in the module which I wanted to analyse. But when I analyse the project using sonar scanner, analysis failed and below error can be seen in server logs. So is there anyway to analyse only one module in multi module project?
org.sonar.api.utils.MessageException: Validation of project failed:
o Component (uuid=AV7hl7plAY-wqGulFkbZ, key=child-key) is not a project
o The project "child-key" is already defined in SonarQube but as a module of project "parent-project-key". If you really want to stop directly analysing project "parent-project-key", please first delete it from SonarQube and then relaunch the analysis of project "child-key".
Having analyzed the modules together as one project, you cannot then go back and analyze only one of them. All modules must be analyzed together or you must delete your aggregate project to allow module analysis on an individual basis.
Note that the Governance($) plugin would allow you to re-aggregate your split modules

SonarQube and migration to multi-module project with preserving history

We're in process of migration of a single Maven project that has been analyzed in SonarQube 4.5.4 into a multi-module Maven project.
The SonarQube analyzing is going to be migrated to the Parent project so that the old and new modules would be analyzed all-in-one.
During the analyzing we receive an error:
'The project '...' is already defined in SonarQube but not as a module of project '...:Parent''
The obvious solution is to remove the old project from SonarQube, however it means removal of all historical information.
How can we achieve both goals:
migrate to multi-module project
keep history of analyzing of the existing project (that should be a child of the new multi-module project)
?
Thanks.
SonarQube does not allow to group several existing projects into a single one. So you won't be able to achieve your 2 goals.
The only thing you can do is to update the key of each existing project on SonarQube (for instance, you can add "_OLD" suffix on their key). This will allow you to:
Keep the history for those projects - but they won't evolve any longer
Make it possible to analyze successfully the new multi-module project
To know how to update project key, please read the documentation.

How do I create a project based on multiple poms and allow refactoring between them?

Let's say I have several poms with dependencies on each other. There's a class in one project that is used in several others. I want to perform a refactoring (like rename on that class) that updates all the projects.
I tried to accomplish this by adding the maven projects via the Maven Projects pane. This lets me see all the code and compile, but when I try to refactor, I get an error message saying "Cannot perform refactoring. Selected field is not located inside project." How can I make all these maven projects behave like a single project?
edit Pebkac strikes again. I had problems with my poms. I fixed those, and now everything works as expected.
You want a multi-module maven project, with the modules defined in a parent pom. You then tell idea to create or open a project from the parent pom. All modules then form part of the project, and your refactorings should work.

Jenkins Sonar plugin throws duplicate source file error during analysis

I have set up Sonar with MySQL Database. My project is a multi module eclipse project, which means it has multiple plugins.
I have set up a Jenkins build with Maven to build this project and also installed Jenkins Sonar plugin to analyse the code with sonar.
All the configurations seem to be correct. However, when sonar tries to analyse this project after the build, it complains of duplicate source code and the build fails.
Each eclipse plugin has Activator.java class and Sonar complains that this is duplicate. I have excluded this class from analysis, but Sonar complains of classes in a particular plugin that is added as a dependency to lot other plugins.
Incomplete analysis of the code leads to other issues in Sonar for this project. like, even though the project is visible in the Sonar dashboard, it asks for authentication again on clicking the project, even though I am logged in as admin.
Any inputs on pointing me to the right direction would be very helpful.
Please let me know if any additional inputs are necessary to better understand my problem.
IMO, the best example you can follow is our Sonar Eclipse project: https://github.com/SonarSource/sonar-eclipse. This is also a multi-module Eclipse project.
In this example, you want to have a look at the parent module (https://github.com/SonarSource/sonar-eclipse/tree/master/org.sonar.ide.eclipse.parent) which goal is only to define the parent POM. Almost everything happens there.
I guess that you should find your way thanks to this.
I was able to fix this issue by removing the test tag in the parent pom.xml. This was somehow causing sonar to throw the duplicate source error. It was a tedious task to figure out the root cause and I had to reconstruct pom.xml from scratch, adding section by section.
Thanks to all for the help.

Resources