【发布时间】:2014-11-06 17:47:37
【问题描述】:
我正在尝试根据“Jenkins Continuous Integration Cookbook”一书中的示例实现一个新的 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>
我的 maven 项目的根目录中有文件“password_ruleset.xml”,它看起来如下:
<?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
检查哪些库包含此类,我意识到它本身就是“pmd”。我试图将依赖项添加到依赖项部分,但没有运气。
我应该在哪里改变什么来克服这个问题?
请在 github 中查看整个设置: https://github.com/dave00/pmdcustomrule
【问题讨论】:
-
您使用的是哪个版本的 PMD 插件?
-
我使用的是 maven-pmd-plugin 3.2。请参阅下面的解决方案。