Module level sonar analysis in maven Multi Module project - maven

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.

Related

How can I set-up Maven to create Jacoco coverage for tests for source code another module?

I have a multi-module Maven project. Many of the tests are in the conventional directory (src/test/java) but about 60% are in single module.
By default, Jacoco does not create coverage for those tests.
I'd like the tests in the single module to contribute to coverage.
Nb. We collects coverage in Sonar.
To fix this, set the following configuration item:
<inclNoLocationClasses>true</inclNoLocationClasses>

Can I fail my Maven build based on an existing Karma coverage report?

I use Maven to build a multi-component project. One of the components is a web app with HTML and JavaScript. Maven invokes NPM and Karma to run that component's unit and integration tests, written in QUnit. This yields two independent Cobertura coverage reports that I then combine into one with istanbul-combine.
As a final step, I'd like the Maven build to fail if that combined Cobertura report doesn't satisfy my coverage requirements. But how?
I've tried the Cobertura Maven Plugin, but it seems to be unfit to simply read an existing report and apply its check configuration. First, it needlessly repeats the build's tests ("Invokes the execution of the lifecycle phase test prior to executing itself."), then it finds that it cannot instrument the non-Java resources, then it simply stops, without any log output whatsoever.
Are there other plugins that fit? Could changing the report format help? (Doesn't have to be Cobertura.)

Running multi-module project successfully with error in an module

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.

Integration Test Code Coverage using jacoco and maven

I have a maven test project which tests our dev code. These 2 are different maven projects.
Test project access dev project via maven dependency.
I want to measure integration test code coverage against dev project using jacoco and maven plugin.
Previously I have done it using jacoco and sonar where test code generates jacoco.exec file and then I manually built dev project passing jacoc.exec as arg in jenkins and get code coverage report.
I was not basically looking for 100% automated way of doing this.
Have read couple of articles which uses jacoco with maven but all those uses single project.
Appreciate any help/pointer.
Thanks
The 'dirty trick' here is to accumulate Jacoco coverage reports. As you have different projects there is no legal way to do this as by design maven projects are to be built without direct dependency.
But in real world nothing is ideal:
You point JaCoco report file with fixed path. By the way you can do it relatively to your Maven repository which is pretty clean approach.
You build your projects in 2 phases: first phase build all projects running all possible tests. It's better to have separate JaCoco report files per unit and integration tests. But they should be the same among projects and projects shall be configured to accumulate reports.
Doing second pass you run your mvn sonar:sonar magics. This will bring you 2 sonar projects (as I understand now you have the same picture) but coverage will be much more precise. The key is unified reports calculated on previous stage.
Here is complete enough illustration of this idea and lot of references to more simple projects. And here is another question which illustrates idea.
Hope this helps. I do the same approach for my multi-module projects to get coverage for 'lower layer' modules when doing tests for 'higher layer' ones.

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.

Resources