0

有人可以告诉我如何使用 maven 从 PMD 分析中排除某些接口。在进行 Maven 构建时,我遇到了以下异常。

PMD 失败:ILogin$RetrieveLoginInfo_:4 Rule:ConstantsInInterface Priority:3 避免接口中的常量。接口定义类型,常量是更好地放置在类或枚举中的实现细节。参见有效的 Java,第 19 项.. [

我在 pom 的属性中添加了 exclude-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 并没有从 PMD 分析中排除 ILogin 接口。

4

1 回答 1

0

首先,你的结构exclude-pmd.properties不正确。根据https://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html

您应该单独使用规则名称作为值(逗号分隔),所以在这种情况下它应该是:

com.login.ILogin=ConstantsInInterface

话虽如此,我认为您期望该属性具有不同的行为。

pmd:check如果报告的唯一违规是该文件上的违规,这将简单地避免任务失败。它不会从分析中忽略文件。它主要是作为一种在遗留项目上逐步启用 PMD 的方法。

您可能应该对您描述的用例使用不同的方法。

  1. 您可以按照https://pmd.github.io/pmd-6.15.0/pmd_userdocs_suppressing_warnings.html在源代码中简单地抑制此警告
  2. 您实际上可以通过自定义规则集从分析中忽略文件(对于所有规则!),遵循https://pmd.github.io/pmd-6.15.0/pmd_userdocs_making_rulesets.html#filtering-the-processed-files
于 2019-06-13T14:58:25.537 回答