Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar Jacoco Excludes sonar.jacoco.excludes causes 0% coverage instead of ignored.

When I write

<sonar.jacoco.excludes>*.model.*</sonar.jacoco.excludes>

The package is not excluded from instrumentation / reporting and coverage shows as 0%

Why is this ?

Sonar version 3.6

like image 219
MikePatel Avatar asked Jul 10 '13 11:07

MikePatel


People also ask

Does sonar use the JaCoCo Exclusions List?

Yes, presumably. SonarQube reads the report that JaCoCo gives it. If JaCoCo excludes certain classes, then SonarQube shouldn't get any data on them.

How do I ignore code coverage in Sonar?

Ignore Code Coverage To do so, go to Project Settings > General Settings > Analysis Scope > Code Coverage and set the Coverage Exclusions property.

How do I exclude JaCoCo coverage?

Starting from JaCoCo 0.8. 2, we can exclude classes and methods by annotating them with a custom annotation with the following properties: The name of the annotation should include Generated. The retention policy of annotation should be runtime or class.

What is the difference between sonar and JaCoCo?

SonarQube has a broader approval, being mentioned in 163 company stacks & 271 developers stacks; compared to JaCoCo, which is listed in 5 company stacks and 11 developer stacks.


2 Answers

Common pitfall to use the wrong pattern to exclude. Notice the .

Bad :

<sonar.jacoco.excludes>*.model.*</sonar.jacoco.excludes>

Good:

<sonar.jacoco.excludes>*model*</sonar.jacoco.excludes>

Documentation for weary travellers.

like image 78
MikePatel Avatar answered Oct 13 '22 09:10

MikePatel


I am using SonarQube version 4.5 and setting sonar.coverage.exclusions property worked in my case. Official documentation is here.

In your case I suggest to use the following property

sonar.coverage.exclusions=**/model/**/*
like image 31
Mikalai Parafeniuk Avatar answered Oct 13 '22 11:10

Mikalai Parafeniuk