gpt4 book ai didi

maven - PMD with Maven - 如何禁用规则集中的一个规则?

转载 作者:行者123 更新时间:2023-12-04 15:47:20 29 4
gpt4 key购买 nike

我有通过 Maven 2 运行的 PMD。现在我有所有的规则集来查看生成的内容(见下面的代码)。我正在经历并修复对我来说有意义的事情。但是,在某些情况下,例如在“优化”规则集中,我想保留规则集,但是 仅禁用规则集中的一项规则 .就我而言,我想禁用“AvoidInstantiatingObjectsInLoopss”规则。

这是我的 pom.xml 的报告部分

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.6</version>
<configuration>
<linkXref>true</linkXref>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>${pmd.minimumTokens}</minimumTokens>
<failOnViolation>${pmd.failOnViolation}</failOnViolation>
<targetJdk>${projectTargetJdk}</targetJdk>

<rulesets>
<!-- See the FAQ here: http://maven.apache.org/maven-1.x/plugins/pmd/faq.html -->
<!-- See the rule sets here: http://pmd.sourceforge.net/ (menu on the left has a Rule Sets section -->
<!-- Unused rule sets -->
<!-- <ruleset>/rulesets/naming.xml</ruleset> -->

<!-- Unable to find rule sets -->
<!-- <ruleset>/rulesets/emptycode.xml</ruleset> -->
<!-- <ruleset>rulesets/comments.xml</ruleset> -->
<!-- <ruleset>/rulesets/unnecessary.xml</ruleset> -->
<!-- <ruleset>/rulesets/logging.xml</ruleset> -->

<!-- used rule sets -->
<!-- http://pmd.sourceforge.net/rules/java/basic.html -->
<ruleset>/rulesets/basic.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/braces.html -->
<ruleset>/rulesets/braces.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/clone.html -->
<ruleset>/rulesets/clone.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/codesize.html -->
<ruleset>/rulesets/codesize.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/controversial.html -->
<ruleset>/rulesets/controversial.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/coupling.html -->
<ruleset>/rulesets/coupling.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/design.html -->
<ruleset>/rulesets/design.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/finalizers.html -->
<ruleset>/rulesets/finalizers.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/imports.html -->
<ruleset>/rulesets/imports.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/j2ee.html -->
<ruleset>/rulesets/j2ee.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/junit.html -->
<ruleset>/rulesets/junit.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/javabeans.html -->
<ruleset>/rulesets/javabeans.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/migrating.html -->
<ruleset>/rulesets/migrating.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/optimizations.html -->
<ruleset>/rulesets/optimizations.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/strictexception.html -->
<ruleset>/rulesets/strictexception.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/strings.html -->
<ruleset>/rulesets/strings.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/sunsecure.html -->
<ruleset>/rulesets/sunsecure.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/typeresolution.html -->
<ruleset>/rulesets/typeresolution.xml</ruleset>
<!-- http://pmd.sourceforge.net/rules/java/unusedcode.html -->
<ruleset>/rulesets/unusedcode.xml</ruleset>
</rulesets>
</configuration>
</plugin>
</plugins>
</reporting>

最佳答案

规则的定义及其激活位于规则集文件中。
由于您在“规则集”文件夹中有文件的副本,因此只需删除或注释包含规则引用的规则集文件上的节点。
在这种情况下,“AvoidInstantiatingObjectsInLoops”(net.sourceforge.pmd.rules.optimization.AvoidInstantiatingObjectsInLoops)是一个优化规则,所以它很可能在“/rulesets/optimizations.xml”中。

只需编辑文件,查找包含的规则,然后注释或删除相应的规则节点即可。

我不知道您文件的内容,因此您可以多次包含该规则。

关于maven - PMD with Maven - 如何禁用规则集中的一个规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9147938/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com