有人可以告诉我如何使用 maven 从 PMD 分析中排除某些接口(interface)。我在进行 Maven 构建时遇到以下异常。
PMD 失败:ILogin$RetrieveLoginInfo_:4 规则:ConstantsInInterface 优先级:3 避免接口(interface)中的常量。接口(interface)定义类型,常量是更好地放置在类或枚举中的实现细节。请参阅《Effective Java》,第 19 项。 [
我在 pom 的属性中添加了 except-pmd.properties 。这是我在 pom.xml 属性中的条目。
<pmd.excludeFromFailureFile>${project.basedir}/src/etc/exclude-pmd.properties</pmd.excludeFromFailureFile>
排除-pmd.properties 条目:
com.login.ILogin=ConstantsInInterface Priority:3 Avoid constants in interfaces.
界面:
public interface ILogin {
interface RetrieveLoginInfo_ {
int STATUS=0
}
}
但是maven并没有将ILogin接口(interface)排除在PMD分析之外。
最佳答案
首先,您的 exclude-pmd.properties
的结构不正确。根据https://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html
您应该单独使用规则名称作为值(以逗号分隔),因此在本例中它应为:
com.login.ILogin=ConstantsInInterface
话虽这么说,我认为您期望此属性有不同的行为。
如果报告的唯一违规行为是该文件上的违规行为,这将简单地避免 pmd:check
任务失败。它不会忽略分析中的文件。它主要是作为一种在遗留项目上逐步启用 PMD 的方法。
您可能应该对您描述的用例使用不同的方法。
- 您可以简单地在源代码中抑制此警告,如下 https://pmd.github.io/pmd-6.15.0/pmd_userdocs_suppressing_warnings.html
- 您实际上可以通过自定义规则集忽略分析中的文件(对于所有规则!),遵循 https://pmd.github.io/pmd-6.15.0/pmd_userdocs_making_rulesets.html#filtering-the-processed-files
关于java - PMD故障: ILogin:73 Rule:ConstantsInInterface Priority:3 Avoid constants in interfaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56570661/