SonarQube "Duplicated Lines on New Code" gate failure in CI
The quality gate caps the percentage of duplicated lines on new code, commonly at 3%. Your change added blocks that Sonar detected as duplicates, pushing new-code duplication over the limit.
What this error means
The gate reports "Duplicated Lines (%) on New Code" above the required maximum. The measures tab lists the duplicated blocks Sonar found in the changed files.
QUALITY GATE STATUS: FAILED
6.8% Duplicated Lines (%) on New Code (required <= 3.0%)Common causes
Copy-pasted code in the changed files
The change repeats a block that already exists, or repeats within the same change, and Sonar flags the duplicated lines.
Generated or vendored files are being analyzed
Large generated files can look duplicated. If they are not excluded, they inflate the duplication ratio on new code.
How to fix it
Refactor the duplicated blocks
- Open the Duplications view for the changed files on the dashboard.
- Extract the repeated logic into a shared function or module.
- Re-run the scan to confirm new-code duplication is back under the cap.
Exclude generated code from duplication detection
If the duplication comes from generated or vendored files, exclude them so real code is measured accurately.
sonar.cpd.exclusions=**/generated/**,**/*_pb2.pyHow to prevent it
- Factor shared logic into helpers instead of copying blocks.
- Exclude generated and vendored code from analysis.
- Review the Duplications view on the PR before merging.