Running multi-module project successfully with error in an module - sonarqube

Starting position:
SonarQube 4.5.2
SonarRunner 2.4
Multi-module project
4 modules
Goal: To run the sonar analysis for the modules, even if the sonar analysis of a module fails. And show the metrics of the multi-module project.
The problem is, if the sonar analysis of one module fails, the sonar analysis of the whole multi-module project fails. And I can't see anything in my SonarQube webbrowser.
My idea was that I run the sonar analysis for each module separately, but with the Project.Key of the module in the Multi-module project. The problem is that SonarQube creates a separate project with this Project.Key and "deletes" the module in the multi-module project.
Do you have any suggestion how to realize the mentioned goal?
Thanks in advance.

This is not possible. If one of your modules fail to be analyzed correctly, simply remove it from your configuration.

Related

Module level sonar analysis in maven Multi Module project

While building from my Parent module, the code coverage and sonar anslysis happens fine. Since Sonar does aggregation of code coverage of all sub modules.
However, When I build my sub-module for code coverage, the analysis is not updated back in my Parent project.
Is there a way to tweak the aggregation both ways, i.e. When Parent build happens or when an individual Module builds independently. I don't want to run the whole parent project everytime, to capture the code coverage analysis in sonar.
My parent pom.xml consists of all sonar,jacoco configurations and other modules inherit them.
<sonar.jacoco.reportPaths>${project.basedir}/../target/*ut-jacoco.exec</sonar.jacoco.reportPaths>
And each module generates its own moduleX-ut-jacoco.exec.
Thanks #khmarbaise for guidance. It took a while to understand the behavior but its indeed a learning.
After Module is build with test-case execution using
mvn clean install
A separate sonr analysis is needed to be run on parent project.
mvn sonar:sonar
This subsequent sonar analysis helped me update coverage and other metrics on Parent porject as well as at Module level.

Differences between sonar-maven-plugin and sonar-scanner

We currently use the sonar-scanner utility to run sonar analysis on our maven multi-modules java project.
I wanted to move from the sonar-scanner to the sonar-maven-plugin, but the first tests shows a big discrepancy in the reported metrics.
For example the number of lines of code went from 466'000 to 154'000.
The main difference seems to be that the maven plugin does not analyse the src/test directories whereas the scanner does. Another reason could be that the maven plugin only analyses the modules which are enabled.
Do this behavior seems normal to you ?
or did I miss some configuration in the plugin or the scanner. They both should pull the config from our sonarqube server.
If this is the normal behavior then should I stay with the scanner and keep the metrics history or should I start over with the maven plugin ?
I could redo some analysis for all versions we released to have some comparisons and trends.
Thanks for your advices.
Update:
Settings the sonar.sources and sonar.inclusions like mentioned there gives some better results...
sonar-maven-plugin: extending sonar.sources in multi-module 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.

Sonar separate quality profile per component

I have a multi-module maven project and have it's modules as Sonar components.
Is it possible to set alerts separate per module/component, or Sonar considers the whole project? If not, what's the best way of having my maven modules as separate projects in Sonar, so that mvn sonar:sonar is only executed once. I use cobertura for report generation.
At the moment of writing this answer, that feature is not supported by Sonar.
If separate metrics needed you need to create a separate project and trigger a separate build from Jenkins and providing specific pom.xml file for desired module.

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