PMD/checkstyle/findbugs的自定义规则集的建议位置是什么?

Wim*_*uwe 5 findbugs checkstyle pmd maven

将Maven与PMD,Checkstyle和/或Findbugs的各种插件一起使用时,放置自定义规则集文件的推荐位置是什么?

Krz*_*soń 2

我通常将它们放在一个单独的父 pom 中,这样我以后就可以在其他模块或项目中重用它们。与 checkstyle 页面( https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html )上的提议类似,但我将其保留在主项目之外。

您将文件放置在一个名为build-toolssrc/main/resources/your/package 的模块中,并带有 checkstyle 和 pmd config,然后使用以下命令配置给定的插件:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.17</version>
    <dependencies>
      <dependency>
        <groupId>com.example.whizbang</groupId>
        <artifactId>build-tools</artifactId>
        <version>1.0</version>
      </dependency>
    </dependencies>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

FindBugs 比较棘手,我通常保持原样,有时只使用@SuppressFBWarningsfrom:

   <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>3.0.1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)