我正在尝试使用PMD向现有的Maven构建添加JSP ruleset。不幸的是,似乎无论我做什么我都会收到错误。如果我添加对现有规则集的引用:
<rule ref="rulesets/jsp/basic.xml/NoUnsanitizedJSPExpression" />
我收到此消息(添加了换行符以提高可读性:
Execution DRY of goal org.apache.maven.plugins:maven-pmd-plugin:2.7.1:pmd failed:
Couldn't find that class Can't find resource rulesets/jsp/basic.xml.
Make sure the resource is a valid file or URL or is on the CLASSPATH -> [Help 1]
我咨询过this question并尝试了各种前导斜杠的排列:
<rule ref="/rulesets/jsp/basic.xml/NoUnsanitizedJSPExpression" />
但我仍然收到上面引用的错误消息。
我尝试将规则集添加到Maven插件(第二个规则集):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<rulesets>
<ruleset>${project.basedir}/src/main/resources/properties/pmd_workspace.xml</ruleset>
<ruleset>rulesets/jsp/basic.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<id>DRY</id>
<phase>test</phase>
<goals>
<goal>cpd</goal>
<goal>pmd</goal>
</goals>
</execution>
</executions>
</plugin>
但这只是给了我这个错误:
An error has occurred in PMD Report report generation. Could not find resource 'rulesets/jsp/basic.xml'. -> [Help 1]
我查看了PMD和Maven PMD插件的文档,但没有运气。任何人都可以帮助或指点我的教程吗?
答案 0 :(得分:0)
原来是因为我使用的是旧版Maven PMD插件。 Maven插件自己拉入PMD,这很方便,但是不能让你控制它所引入的版本。
我使用的版本2.7.1在PMD版本4.3中提取,它没有我试图包含的规则。因此,它(正确地)表示它找不到该规则。
当前版本的Maven PMD插件3.3引入了PMD版本5.2.1,其中包含NoUnsanitizedJSPExpression
JSP检查规则。
一旦我将maven PMD插件更新到版本3.3,一切正常:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.3</version>
<configuration>
<rulesets>
<ruleset>${project.basedir}/src/main/resources/properties/pmd_workspace.xml</ruleset>
</rulesets>
</configuration>
</plugin>