How to update only one module in multi module project - sonarqube

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

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.

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

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.

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.

maven multi-module project with one plugin module

I am thinking about creating a multi-module project in maven, with one plugin module (i.e. this module is used as a plugin in other projects, not a dependency).
Question: Is it feasible to have a plugin as a module in a multi module maven project?
It is feasible and it is also documented on the official maven multi-module/reactor page concerning how having a plugin as module is handled by the build (bold is mine):
Because modules within a multi-module build can depend on each other, it is important that The reactor sorts all the projects in a way that guarantees any project is built before it is required.
The following relationships are honoured when sorting projects:
a project dependency on another module in the build
a plugin declaration where the plugin is another modules in the build
a plugin dependency on another module in the build
[..]
Once the plugin is installed and deployed, it will then not bring with it any knowledge of its module nature, that is, it will be seen as a normal plugin by the projects that will use it via its unique maven coordinates (GAV).
The same is applied to archetypes, which can be modules of a multi module project and then be used individually.
Also note that you can have - as an example - an aggregator project of projects (then modules) completely unrelated between each other, and, say, just aggregate then because you want to build them all together (often not really meaningful, but useful in some cases).

Unable to run SonarQube analysis of two projects with the same ids?

I have a situation like where i have two projects.
For one project i am successfully able to run analysis. 2nd project is new and it is completely using code and same structure and same modules of project 1 and we can say it is extension of Project 1. While i am running code analysis it is saying modules are already part of project 1
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7.1:sonar
(default-cli) on project citi-sgp-au:
Module "com.xxxx.xxxx:xxxxxx" is already part of project "xxxx-xxx-xxx222"
-> [Help 1]
Any guidance on this?
SonarQube cannot analyze 2 different projects with the same id (e.g. groupId and artifactId).
You can change id of one of the two projects or use sonar.branch property.
From SonarQube Wiki:
sonar.branch - Manage SCM branches. Two branches of the same project are
considered to be different projects in SonarQube. As a consequence
issues found in a project A in a branch B1 are not linked to issues
found for this project A in a branch B2. Currently, there is no way to
resolve automatically issues of B2 when they are resolved in B1 as
again A-B1 & A-B2 are considered as separated project.
Because you are using the same code and same structure, I assume that the module of both projects end up having the same key. In SonarQube, it is not possible to have a module that belongs to several projects.
So the solution is to make sure that the modules of your 2nd project have unique keys.
Note: if you're using Maven, this is very simple: just make sure that your second project has a different groupId.

Resources