我正在尝试基于“Jenkins Continuous Integration Cookbook”一书中的示例实现新的XPath PMD规则。如何使用Maven为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>
我的文件“password_ruleset.xml”坐在我的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']
]]>
在执行我得到以下错误:
Failure executing PMD: Couldn't find the class net.sourceforge.pmd.rules.XPathRule
检查哪些库包含此类我意识到它' s'pmd'本身。我试图将依赖项添加到依赖项部分,但没有运气。
我应该改变什么来克服这个问题?
请参阅整个安装在github上: https://github.com/dave00/pmdcustomrule
您使用的是哪个版本的PMD插件? – user944849 2014-11-07 16:43:51
我使用的是maven-pmd-plugin 3.2。请参阅下面的分辨率。 – dbalakirev 2014-11-08 13:53:05