如何使用Maven为PMD创建自定义规则?

时间:2014-11-06 17:47:38

标签: java maven pmd

我正在尝试基于本书" Jenkins持续集成手册"中的示例实现新的XPath PMD规则。

我的pom文件的相关部分:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>2.1</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <configuration>
                <targetJdk>1.6</targetJdk>
                <format>xml</format>
                <rulesets>
                    <ruleset>password_ruleset.xml</ruleset>
                </rulesets>
            </configuration>
        </plugin>
    </plugins>
</reporting>

我有文件&#39; password_ruleset.xml&#39;坐在我的maven项目的根目录,它看起来如下:

<?xml version="1.0"?>
<ruleset name="STUPID PASSWORDS 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">
  <description>
  Lets find stupid password examples
  </description>
<rule name="NO_PASSWORD"
  message="If we see a PASSWORD we should flag"
  class="net.sourceforge.pmd.rules.XPathRule">
  <description>
  If we see a PASSWORD we should flag
  </description>
  <properties>
    <property name="xpath">
    <value>
<![CDATA[
//VariableDeclaratorId[@Image='PASSWORD']
]]>

执行时我收到以下错误:

  

执行PMD失败:无法找到类net.sourceforge.pmd.rules.XPathRule

检查哪个图书馆包含这个课程,我意识到它已经实现了这样的课程。本身。我试图将依赖项添加到依赖项部分,但没有运气。

我应该在哪里以及应该改变什么才能克服这个问题?

请参阅github中的整个设置: https://github.com/dave00/pmdcustomrule

1 个答案:

答案 0 :(得分:1)

我的一个朋友通过github解决了我的问题:  https://github.com/mnyeste/pmdcustomrule/commit/ad2f04e33d2a5a04ef95d059d64a258ebca5b7be

要点:

  

PMD API更改4.3 - &gt; 5.0类net.sourceforge.pmd.rules.XPathRule   已重命名为net.sourceforge.pmd.lang.rule.XPathRule

     

Maven PMD插件3.2版正在使用PMD 5.1.2

任何感兴趣的人现在都可以从github中获取我的示例项目,看看它是否正常工作。

相关问题