我只是想将PMD添加到我的Spring Boot项目中,但是在尝试从category/java/errorprone.xml
规则集中排除某些规则时遇到了一些问题。
我正在使用gradle插件,如下所示:
pmd {
ruleSetConfig = resources.text.fromFile("config/pmd/ruleset.xml")
}
这是我的自定义规则集文件的内容:
<?xml version="1.0"?>
<ruleset>
<rule ref="category/java/bestpractices.xml"></rule>
<rule ref="category/java/codestyle.xml">
<exclude name="MethodArgumentCouldBeFinal"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="ControlStatementBraces"/>
<exclude name="OnlyOneReturn"/>
<exclude name="ConfusingTernary"/>
<exclude name="AtLeastOneConstructor"/>
<exclude name="AvoidFinalLocalVariable"/>
<exclude name="ShortVariable"/>
<exclude name="LongVariable"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="DefaultPackage"/>
<exclude name="PrematureDeclaration"/>
</rule>
<rule ref="category/java/design.xml">
<exclude name="LawOfDemeter"/>
<exclude name="NcssCount"/>
<exclude name="CyclomaticComplexity"/>
<exclude name="UseUtilityClass"/>
<exclude name="AvoidCatchingGenericException"/>
<exclude name="NPathComplexity"/>
<exclude name="AvoidRethrowingException"/>
<exclude name="DataClass"/>
<exclude name="AvoidThrowingRawExceptionTypes"/>
</rule>
<rule ref="category/java/documentation.xml">
<exclude name="CommentRequired"/>
<exclude name="UncommentedEmptyConstructor"/>
<exclude name="CommentSize"/>
</rule>
<rule ref="category/java/errorprone.xml">
<exclude name="BeanMembersShouldSerialize"/>
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="AssignmentInOperand"/>
</rule>
<rule ref="category/java/multithreading.xml">
</rule>
<rule ref="category/java/performance.xml">
<exclude name="AvoidInstantiatingObjectsInLoops"/>
</rule>
<rule ref="category/java/security.xml">
</rule>
</ruleset>
如您所见,我同时排除了BeanMembersShouldSerialize
和DataflowAnomalyAnalysis
,但在PMD报告中仍然出现这些错误:
Found non-transient, non-static member. Please mark as transient or provide accessors.
`发现变量'userEntity'的'DU'异常(行'28'-'38')。``
我使用的是PMD版本6.10.0(2018年12月9日)。
任何帮助将不胜感激。
致谢
答案 0 :(得分:8)
Gradle默认使用basic
和braces
规则集,直到Gradle5。Gradle 5默认使用errorprone
类别。
如果您不想这样做,则需要清除以下默认值:
pmd {
ruleSets = []
}