PMD找不到规则集 [英] PMD coulnd't find ruleset
问题描述
我正在创建一个基于maven的java项目,其中包含PMD maven插件。我使用自己的规则集XML,它就像一个魅力,除了两个规则集:空码和不必要:当我运行构建时,maven说:找不到资源。角色定义如下所示:
I'm on creating a maven based java project, which contains the PMD maven plugin. I use my own rule set XML and it works like a charm, except two rule sets: the emptycode and the unnecessary: when I run the build, maven says: "can't find resource". The role definitions look like:
<role ref="rulesets/emptycode" />
和
<role ref="rulesets/unnecessary" />
在其他所有情况下,这种定义都有效。我发现的是:在 ecmasrcipt 类别下有一个名为不必要的规则集,所以这个定义可能需要一些使用java版本的建议。我尝试了多次思考,比如将 language 属性设置为规则集 xml节点(JAVA,基于PMD JavaDoc),以及 ref <中的一些前置后缀/ em>,但它不起作用,我在网上找不到可行的解决方案。有人有想法,我忘记了什么,或者我失败了什么?感谢您的帮助!
In every other cases, this kind of definition works. What I found out is that: there is a rule set with the name "unnecessary" under ecmasrcipt category, so maybe this definition needs some suggestion to use java version. I tried multiple thinks, like set language attribute to the ruleset xml node ("JAVA", based on PMD JavaDoc), and some pre-postfix in ref, but it doesn't work and I found no working solution over the web. Does someone has an idea, what I forgot to set, or what I fail? Thanks for any help!
推荐答案
PMD似乎是一个可以从Maven中使用的狡猾的野兽。我刚刚用插件的3.0版来解决这个问题 - 有两个解决方案:
PMD seems to be a fiddly beastie to use from Maven. I've just figured this out with version 3.0 of the plugin - there are two solutions:
-
快速 - 和脏解决方案:在你的项目中放置规则集:
The quick-and-dirty solution: put rulesets in your project:
- 下载PMD jar( http://sourceforge.net/projects/pmd/files/latest/download )
- extract
lib / pmd-xxxjar
- 从该PMD jar文件中提取
规则集/< type> /< ruleset> .xml
您要使用的文件 - 将它们放在项目下的文件夹中 - 类似
$ {basedir} / pmd /...
-
引用它们如下:
- download the PMD jar (http://sourceforge.net/projects/pmd/files/latest/download)
- extract
lib/pmd-x.x.x.jar
- extract from that PMD jar file the
rulesets/<type>/<ruleset>.xml
files you want to use - place them in a folder under your project - something like
${basedir}/pmd/...
reference them as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<rulesets>
<ruleset>${basedir}/pmd/<ruleset>.xml</ruleset>
</rulesets>
</configuration>
</plugin>
优点是这很容易,缺点是如果你将来更新PMD版本你会需要记住更新这些文件。
The advantage is this is easy, the disadvantage is if you update the PMD version in future you'll need to remember to update these files.
好的解决方案:参考 pmd-xxxjar
中的规则集。
The nice solution: reference rulesets in pmd-x.x.x.jar
.
- 创建自定义规则集,例如:
$ {basedir} /pmd/custom.xml
(参见 http://pmd.sourceforge.net/pmd-5.0。 2 / howtomakearuleset.html ) - 以下列方式引用PMD规则集:
< rule ref =rulesets / java / imports.xml />
- NB:路径是
pmd-xxxjar $ c内的路径$ c>(请参见上面的快速而肮脏)没有前导斜杠
-
引用您的自定义规则集,如下所示:
- create a custom ruleset such as:
${basedir}/pmd/custom.xml
(see http://pmd.sourceforge.net/pmd-5.0.2/howtomakearuleset.html) - reference the PMD rulesets in the following way:
<rule ref="rulesets/java/imports.xml"/>
- NB: the path is the path inside
pmd-x.x.x.jar
(see quick-and-dirty above) with no leading slash reference your custom ruleset as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<rulesets>
<ruleset>${basedir}/pmd/custom.xml</ruleset>
</rulesets>
</configuration>
</plugin>
优点是它总是会引用PMD jar中的当前PMD规则集,缺点是它是一个为了得到正确的一点点。
The advantage is this will always reference the current PMD rulesets from the PMD jar, the disadvantage is it's a bit fiddly to get right.
试验这个直到它工作( maven-pmd-plugin
3.0版)我一直在运行mvn pmd:pmd(< linkXref> false< / linkXref>
in pom.xml
)并调整路径,直到我停止收到错误。
To experiment with this until it was working (maven-pmd-plugin
version 3.0) I kept running mvn pmd:pmd (<linkXref>false</linkXref>
in pom.xml
) and tweaked the paths until I stopped getting errors.
这篇关于PMD找不到规则集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!