How to Exclude Generated Code From Quality Analysis
sonar.exclusions removes files from analysis entirely; coverage and duplication exclusions narrow specific metrics.
Set sonar.exclusions for files that should not be analyzed at all, sonar.coverage.exclusions for files that skew coverage, and sonar.cpd.exclusions for duplication. Globs are relative to the project base.
sonar-project.properties
sonar-project.properties
sonar.projectKey=my-org_my-repo
sonar.sources=src
sonar.exclusions=**/*.pb.go,**/generated/**,**/vendor/**
sonar.coverage.exclusions=**/*.config.js,**/migrations/**
sonar.cpd.exclusions=**/*.generated.tsExclusion property reference
| Property | Removes from |
|---|---|
| sonar.exclusions | All analysis (issues + metrics) |
| sonar.coverage.exclusions | Coverage measurement only |
| sonar.cpd.exclusions | Duplication detection only |
| sonar.test.exclusions | Test file analysis |
Gotchas
- Full
sonar.exclusionsalso hides real bugs in those files; exclude only truly generated code. - Globs are POSIX-style with
**; a leading/anchors to the base directory.
Related guides
How to Fail CI on Code DuplicationBlock a pull request when duplicated code exceeds a threshold, using a SonarQube duplicated_lines_density gat…
How to Set Coverage, Duplication, and Maintainability Thresholds in a Quality GateDefine quality-gate conditions in SonarQube for minimum coverage, maximum duplicated lines, and a maintainabi…