SonarCloud doesn't exclude specific folder

I have used sonar.exclusions property before and it works as expected. Although in a recent project I can’t find a way to exclude a folder that is a system folder that contains more than 25k lines of CSS code.

The folder path that I need to exclude is: src/CommerceApp.Web/_SystemResources

I have tried setting up the sonar.exclusions in:

  • Prepare analysis on SonarCloud pipeline task.
  • In SonarCloud UI (Analysis Scope).

But none of the above options work.

I have even tried to exclude everything with **/** to test but not even that pattern works.

Do you have any suggestions? Is the folder name _SystemResources a keyword that is preventing SonarCloud to exclude that folder?

Any help is appreciated.

Hi @caraujo84

Just to be clear, to exclude all files and sub-directories under this folder, the setting should be:

sonar.exclusions = src/CommerceApp.Web/_SystemResources/**

Just to be clear by “does not work”, I assume you mean that the files you are trying to exclude from the analysis are still visible when you browse the Code tab of your project on SonarCloud UI. If you mean something else, please clarify!

Since sonar.exclusions = **/** should indeed exclude everything from sources (do not analyze, and will not show up on Code tab), I suspect we’re missing something.

I think it may be useful to review the effective settings related to the analysis. Please go to Administration / Background Tasks page of your project, pick a task where you tried to apply sonar.exclusions = src/CommerceApp.Web/_SystemResources/**, and from the dropdown menu at the right, select Show SonarScanner Context, and copy-paste from it the content of “Project server settings” and “Project scanner properties” sections. I’m mainly interested in the sonar.sources, sonar.exclusions and sonar.inclusions settings. If you prefer to share privately, just let me know and I’ll start a private thread. Here’s an example extract:

Project server settings:
  - sonar.autoscan.enabled=true
  - sonar.exclusions=src/CommerceApp.Web/_SystemResources/**
Project scanner properties:
  - sonar.coverage.exclusions=**/*
  - sonar.exclusions=**/,**/*.cs,**/*.c,**/*.h,**/*.cc,**/*.cpp,**/*.cxx,**/*.c++,**/*.hh,**/*.hpp,**/*.hxx,**/*.h++,**/*.ipp,**/*.m,**/*.java,**/*.jav,**/*sql,**/*tab,**/*pkb,**/*.vb,src/CommerceApp.Web/_SystemResources/**
  - sonar.sources=.
  - sonar.test.exclusions=**/*.cs,**/*.c,**/*.h,**/*.cc,**/*.cpp,**/*.cxx,**/*.c++,**/*.hh,**/*.hpp,**/*.hxx,**/*.h++,**/*.ipp,**/*.m,**/*.java,**/*.jav,**/*sql,**/*tab,**/*pkb,**/*.vb

Hi @janos

Here is more additional information.

I just added the above value as you suggested, still have the same behavior, css and scss files under that folder still show up.

Correct, I can’t find a way to exclude and avoid having the files under that path in the Code tab in my project in SonarCloud. Additionally all the css, scss files are analyzed and counted as part of lines of code. The number of lines from these files is around 25k.

Could you please create a private thread so I can share those additional details?

Thank you!


We were able to resolve this in a private thread, here’s the gist.

The best approach to find why the exclusion pattern is not effective is to look at the output of the scanner in debug mode. This output should include the paths of all files of the project as the scanner saw them. You could then compare those paths with the exclusion pattern. The expectation is that you will see a mismatch, which will explain why the exclusion didn’t work.

Based on the above, Carlos found that the project was being considered as a test project and that is why the regular project exclusion wasn’t picked up by the analyzer.

After setting the exclusion as test exclusions, the folder was correctly excluded.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.