Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar exclusions/inclusions

I'm trying to improve the coverage reports for my project and I want to exclude some packages BUT INCLUDING subpackages. For instance, I have this structure

src/main/java/com/myapp
    └ model
        └ mapper
            └ SomeMapperClass.java
        └ SomeModelClass.java --> exclude this and others...
        └ ...
        └ ClassToInclude.java --> but include this
    └ service

and I want to exclude model package but include mapper and ClassToInclude. Is there any way to do this without having to add every excluded class one by one? I would want something like this in pom.xml:

<sonar.coverage.exclusions>
    **/model/**/*.java
</sonar.coverage.exclusions>
<sonar.coverage.inclusions>
    **/model/mapper/**/*.java
    **/model/ClassToInclude.java
<sonar.coverage.inclusions>

Any help, guide, options and/or workarounds is appreciated. Thanks in advance for your answers.

UPDATE #1

I found a way to include the subpackages only using sonar.coverage.exclusions property by doing:

<sonar.coverage.exclusions>
    **/model/*.java
</sonar.coverage.exclusions>

With this you exclude every class in model but not in model.mapper. Now I just need a way to solve how to include specific class in an excluded package.

like image 834
Alvaro Pedraza Avatar asked May 21 '18 15:05

Alvaro Pedraza


1 Answers

While you can exclude some files from coverage, you can only include files as a whole. That is, exclusion is granular, but inclusion is not (i.e. sonar.coverage.inclusions doesn't exist), so I don't think this will work the way you're currently trying to do it.

That said, this should be doable with only exclusions if you craft them carefully, i.e. **/model/*.java rather than **/model/**/*.java.

like image 74
G. Ann - SonarSource Team Avatar answered Nov 16 '22 03:11

G. Ann - SonarSource Team