How to exclude whole folder but keep certain files?

Hi guys. I am using SonarQube Cloud to analyse coverage from my codebase. I have a structure like:

/**importantPackage1**
/**importnatPackage2**
/nonImportantPackage3
    nonImportantPackage3/**ImportantFile**.kt
    nonImportantPackage3/NonImportantFile.kt
    nonImportantPackage3/...

The thing is: I want to exclude “nonImportantPackage3” but I want to keep “ImportantFile” within it. I tried this:

[...]
        property "sonar.coverage.exclusions", "**/otherNonImportatnPackage/**/* ," +
                "**/nonImportantPackage3/**/*"
        property "sonar.coverage.inclusions", "**/nonImportantPackage3/**/*ImportantFile.kt"
        [...]

But it didn’t work, is there something I’m missing here?

Thanks

Hi,

Welcome to the community!

First, sonar.coverage.exclusions only excludes code from consideration for coverage metrics.

If you want to completely ignore code, then you should be dealing with a plain sonar.exclusions parameter. However, in your case I would actually recommend sonar.inclusions instead. E.G.

sonar.inclusions=**/importantPackage1/**/*, **/importantPackage2/**/*, **/nonImportantPackage3/**/ImportantFile.kt

Note here how I’ve specified the paths with /**/, because the recognized patterns are:

  • ** 0-n directories
  • * 0-n characters

Now, if we weren’t dealing with wildcards, I’d just tell you to narrow sonar.sources:

sonar.sources=foo/bar/importantPackage1, foo/baz/importantPackage2, foo/biz/NonImportantPackage/ImportantFile.kt

 
HTH,
Ann