Sonar.coverage.exclusions not excluding too much

When adjusting this field in the sonarqube-project.properties file, it looks like files get excluded in the code, but even ones that aren’t included. Also, it seems like we can’t add files back to the coverage count. For example, we were able to exclude things from the package “model” with /model/, but for testing purposes when we wanted to see the coverage of files in the model package again, we removed /model from the exclusions list, but those files were still excluded in the analysis. Any help appreciated. Thank you

Hi,

Welcome to the community!

To help you, we’ll need a little more detail. How about

  • your exact exclusion value
  • your analysis logs
  • maybe some indication of your project structure with what’s included/excluded that should [not] be

 
Ann

Hi,

Thank you!

Right now, our exact exclusion value is

sonar.coverage.exclusions=**/test/**, **/api/**, **/queue/**, **/model/**

Our analysis logs are attached here: sonarqubeAnalysisLog.txt (14.9 KB)

Our project structure is contained within the root directory src/main/java with packages such as com.x.mailrter.api, com.x.mailrter.queue, com.x.mailrter.model, etc. contained within that. Right now, we’re simply trying to exclude the packages, test, api, queue, and model. However, that being said, we would also like to eventually be able to exclude specific files within a package from the coverage analysis. Right now, though, it looks like even just trying to exclude the test, api, queue, and model packages is not working.

Hi,

Thanks for providing everything I asked for! Your exclusions pattern tells the tail. ** means 0-n directories. Your patterns don’t exclude any files. For that you want:

sonar.coverage.exclusions=**/test/**/*.*, **/api/**/*.*, **/queue/**/*.*, **/model/**/*.*

Note that the pattern update I’ve made assumes you’re using file extensions.

 
HTH,
Ann

Hm, it looks like the behavior didn’t change even after replacing with the exclusion pattern you provided. We are also still getting these messages in the logs

INFO: Excluded sources: **/backout/**, **/config/**, **/Config/**, **/Application.*, **/test/**
[128](https://git.nmlv.nml.com/nb/underwriting/mailrtr/mailrouter/-/jobs/19000651#L128) INFO: Excluded sources for coverage: **/test/**/*.*, **/api/**/*.*, **/queue/**/*.*, **/model/**/*.*
[129](https://git.nmlv.nml.com/nb/underwriting/mailrtr/mailrouter/-/jobs/19000651#L129) INFO: 117 files indexed
[130](https://git.nmlv.nml.com/nb/underwriting/mailrtr/mailrouter/-/jobs/19000651#L130) INFO: 0 files ignored because of inclusion/exclusion patterns
[131](https://git.nmlv.nml.com/nb/underwriting/mailrtr/mailrouter/-/jobs/19000651#L131) INFO: 0 files ignored because of scm ignore settings

Full log (sonarqubeAnalysisLog.txt (15.3 KB)

Any feedback? Thanks!

Hi,

Where are you specifying your exclusions. You say you’ve corrected the pattern but the analysis log still reflects the old version. That sounds like you’re providing this both through the UI and in analysis parameters. Precedence is documented here. Exclusions can get a little iffy when provided as analysis parameters. I advise using the UI to set them.

 
Ann

Hi -
Currently configuration (ie. exclusion specification) is being done through direct editing of the sonar-project.properties file. It looks like from the precedence file that this should override the UI. That being said, how can I use the UI to change these settings if the .properties file is not enough? Im not seeing a “Project Settings” option

Thanks, Brianna

Hi Brianna,

sonar-project.properties does take precedence, and since you don’t appear to have Admin on the project, it’ll have to do for now. I’m looking again at your analysis log. It looks like only 1 of 2 parameters was edited…?

 INFO:   Excluded sources: **/backout/**, **/config/**, **/Config/**, **/Application.*, **/test/**
 INFO:   Excluded sources for coverage: **/test/**/*.*, **/api/**/*.*, **/queue/**/*.*, **/model/**/*.*

I see the correct patterns for coverage but not for sources.

 
Ann

Ah gotcha, yes it looks like I did miss editing the “excluded sources” field. Does this still explain why our code coverage analysis looks like its not working?

Well, that is a lot of exclusions…

 
:woman_shrugging:
Ann

Right, I’m just noticing specifically that there’s a few files that should be kept that aren’t showing up on this screen for the coverage analysis of my chore branch

(i.e. there should be a file called

src/main/java/com/nm/mailrouter/mail/handler/AttachmentCAP.java

I’ll try adjusting the “Exclude sources:” field and see if anything changes…

You’re looking at coverage on new code. Does AttachmentCAP.java have new code in it?

 
Ann

Ohhh, okay, no it does not. That clarifies things, thank you!