Excluding files from analysis based on path-matching patterns at the global level
As a system administrator, you can adjust the initial analysis scope at the global level by excluding files based on path-matching patterns. To exclude files, you define file exclusion parameters based on directory and file name patterns. This analysis scope adjustment applies to all projects in your instance. However, they can be overridden at the project level in the UI or through analysis parameters set on the CI/CD host.
Example of an initial scope adjustment
We consider the following repository example where test files are contained in both test/
directories. Source and test code files are contained in the same ancestor directory: src/
which is chosen as the initial analysis scope for both source and test code. Therefore, a scope adjustment is necessary.

We adjust the initial scope as follows:
- For source files: by defining an exclusion parameter with the pattern
src/**/test/**/*

- For test files: by defining an inclusion parameter with the pattern
src/**/test/**/*

Principles governing the use of file exclusion parameters
A file path definition is either relative to the sonar.projectBaseDir
property (which is by default the directory from which the analysis was started, for more information see Analysis parameters) or absolute.
Defining a file exclusion parameter
- Go to Administration > Configuration > General Settings > Analysis Scope.
- In A. File Exclusions, choose the parameter to configure (source or test code; exclusion or inclusion patterns; forced global (indicated by the Global prefix) or not), and enter and save the first pattern. See Defining path-matching patterns.
- Add additional patterns to the parameter if necessary.
- Define other parameters if necessary. Make sure you use either (Global) Source File Exclusions or Source File Inclusions, and either (Global) Test File Exclusions or Test File Inclusions.
Global Source File Exclusions and Global Test File Exclusions are forced global parameters. A forced global parameter applies to all projects and cannot be overridden by any other setting.
Related pages
Was this page helpful?