Version note: references describe SonarQube Server 2025.2 behaviour. Check your server, scanner and edition requirements. These examples were not run against a live SonarQube server.
What this guide covers
Generated code is produced by a tool rather than edited directly. You can exclude some generated files, but the source definition, generator and integration still need review and tests.
Before you start
Identify exactly which files are generated and how to regenerate them. Do not exclude a whole application directory merely because some files inside it are generated.
Step 1: Decide what remains checked
Keep hand-written code and generator inputs in normal review. Test the application code that calls the generated code. Record the generator version and how updates are approved.
Step 2: Choose the smallest exclusion
To remove one generated client from all source analysis, an example setting is:
sonar.exclusions=src/generated/api-client/**
If only coverage or duplication should be excluded, use those narrower settings instead:
sonar.coverage.exclusions=src/generated/**
sonar.cpd.exclusions=src/generated/**
These are alternatives with different effects. Choose and document the one you need.
Step 3: Verify regeneration
Run your project’s documented generation command, then check whether committed generated files changed:
set -eu
# Run the repository's reviewed, pinned generation command first.
git diff --exit-code -- src/generated
The command fails if generated output differs. Investigate the difference instead of silently overwriting it.
Step 4: Review the scan
Run analysis and confirm that the intended files are included or excluded. Recheck the rule when directory names or generator output changes.
Check the result
The exclusion should affect only the intended generated files. Application tests and review of generator inputs should still run.
Conversation
0 commentsNo comments yet. Start the conversation below.