MikePatel
MikePatel

Reputation: 2672

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

Upvotes: 6

Views: 15978

Answers (3)

Titans
Titans

Reputation: 71

I am using sonarqube 10.3.0 and able to ignore the classes in code coverage report using below

<sonar.exclusions>src/main/java/com/<entire_package>/repository/*>
</sonar.exclusions>
<sonar.exclusions>src/main/java/com/<entire_package>/SpringbootWebfluxApplication*>
</sonar.exclusions>

here all classes under repository has been ignored and SpringbootWebfluxApplication class is igonred. Also noticed that only giving core package in exclusion does not work. For example below did not worked

<sonar.exclusions>com/<entire_package>/SpringbootWebfluxApplication*></sonar.exclusions>

where as in case of jacoco, below exclusion worked perfectly fine.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>com/<entire_package>/reposity/*</exclude>                      
            <exclude>
                com/<entire_package>/SpringbootWebfluxApplication.java
            </exclude>
        </excludes>
    </configuration>        
</plugin>           

Find more details here

Upvotes: 0

Mikalai Parafeniuk
Mikalai Parafeniuk

Reputation: 1356

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/**/*

Upvotes: 6

MikePatel
MikePatel

Reputation: 2672

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.

Upvotes: 7

Related Questions