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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With