如何配置SonarQube中common-java:DuplicatedBlocks的最小代码块长度?
Great question—this is a common gotcha because the common-java:DuplicatedBlocks "rule" isn't a typical configurable rule like others, which is why you can't adjust its threshold directly on the rule overview page. Let me break down exactly where to find the setting and how to tweak it:
Global Configuration (applies to all projects)
- Navigate to
Administration > Configuration > General Settings > Duplications(note: this is a separate section from Analysis Scope, which is why you didn't see the line length setting there) - Look for the
Minimum number of linesfield—this controls the threshold for what counts as a duplicated block across all your Java (and other supported) projects - Update the value from the default 10 to your preferred threshold (e.g., 20) and save the changes
- Navigate to
Project-Specific Configuration (overrides global settings for a single project)
If you only want to adjust this threshold for one project instead of all:- Open the target project in SonarQube
- Go to
Project Settings > General Settings > Duplications - Modify the
Minimum number of linesvalue here and save—this will take precedence over the global setting for this project alone
A quick note: After updating the setting, you'll need to re-run your project's analysis for the new threshold to take effect. This should cut down on those false positives from short, unavoidable code blocks that were being flagged as duplicates.
内容的提问来源于stack exchange,提问作者Stefan S.

