【问题标题】:Importing rules in PMD在 PMD 中导入规则
【发布时间】:2018-04-21 05:02:48
【问题描述】:

我们正在实施我们公司的静态分析代码,我们正在尝试 PMD,我已经阅读了 PMD 上的文档,发现不清楚。

我将以下内容添加到我的pom.xml 以下插件中,如文档中所述。

<reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.7</version>
                <configuration>
                    <rulesets>
                        <ruleset>rulesets/java/braces.xml</ruleset>
                        <ruleset>rulesets/java/naming.xml</ruleset>
                    </rulesets>
                </configuration>
            </plugin>
        </plugins>
</reporting>

我不明白的是我在哪里知道规则集的位置以及如何使用我想要使用的规则集创建自己的 XML 文件?

【问题讨论】:

    标签: java maven static-analysis


    【解决方案1】:

    ...规则集的位置...

    • 您从 pom.xml 中提取的内容表明您正在使用 Apache 的 maven-pmd-plugin 版本 3.7。
    • 因此,默认使用的规则集将在本地存储库中的 Apache jar 文件 ma​​ven-pmd-plugin-3.7.jar 中指定。
    • 默认使用的唯一规则集名为 Maven 规则集,并在文件 {Repository location}/maven-pmd-plugin-3.7/rulesets/maven.xml 的 jar 中定义
    • 这是该文件的相关内容:
    <ruleset name="Maven Ruleset"
      xmlns="http://pmd.sf.net/ruleset/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
      xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
      <!--
        Customized PMD ruleset for Maven, see [0] for more information
        [0] https://pmd.github.io/latest/customizing/howtomakearuleset.html
      -->
      <description>
        This ruleset checks the code for discouraged programming constructs.
      </description>
      <rule ref="rulesets/java/basic.xml"/>
      <rule ref="rulesets/java/empty.xml">
        <exclude name="EmptyCatchBlock"/>
      </rule>
      <rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
        <properties>
          <property name="allowCommentedBlocks" value="true"/>
        </properties>
      </rule>
      <rule ref="rulesets/java/unnecessary.xml"/>
      <rule ref="rulesets/java/unusedcode.xml"/>
      <rule ref="rulesets/java/imports.xml"/>
    </ruleset>
    

    ...如何使用我想要的规则集创建自己的 xml 文件 用吗?

    The plugin documentation by Apache describes that,还详细说明了如何在项目之间共享一组通用规则集。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多