2013-02-28 109 views
5

我想行家-PMD-插件包括我指定和排除一些规则(特别是UselessParentheses)不能使用自定义的规则集在Maven的PMD-插件5.0.2

就像documentation描述规则集,我置于pmd.xml以下是所有模块父:

<reporting> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-pmd-plugin</artifactId> 
     <version>3.0</version> 
     <configuration> 
      <rulesets> 
      <ruleset>/home/ubuntu/ruleset.xml</ruleset> 
      </rulesets> 
     </configuration> 
     </plugin> 
    </plugins> 
    </reporting> 

和制备的自定义规则集等与此:

<!-- We'll use the entire rulesets --> 
    <rule ref="rulesets/java/basic.xml"/> 
    <rule ref="rulesets/java/imports.xml"/> 
    <rule ref="rulesets/java/codesize.xml"/> 
    <rule ref="rulesets/java/design.xml"/> 
    <rule ref="rulesets/java/strings.xml"/> 
    <rule ref="rulesets/java/unusedcode.xml"/> 

    <!-- We want everything from this except some --> 
    <rule ref="rulesets/java/unnecessary.xml"> 
    <exclude name="UselessParentheses"/> 
    </rule> 

作为主要组成部分。

尽管如此,当我运行mvn clean jxr:jxr pmd:check我有报告中的“UselessParentheses”。此外,与-X运行它显示

[DEBUG] Preparing ruleset: java-basic 
[DEBUG] Before: java-basic After: java-basic.xml 
[DEBUG] The resource 'rulesets/java/basic.xml' was found as jar:file:/home/ubuntu/.m2/repository/net/sourceforge/pmd/pmd/5.0.2/pmd-5.0.2.jar!/rulesets/java/basic.xml. 
[DEBUG] Preparing ruleset: java-unusedcode 
[DEBUG] Before: java-unusedcode After: java-unusedcode.xml 
[DEBUG] The resource 'rulesets/java/unusedcode.xml' was found as jar:file:/home/ubuntu/.m2/repository/net/sourceforge/pmd/pmd/5.0.2/pmd-5.0.2.jar!/rulesets/java/unusedcode.xml. 
[DEBUG] Preparing ruleset: java-imports 
[DEBUG] Before: java-imports After: java-imports.xml 
[DEBUG] The resource 'rulesets/java/imports.xml' was found as jar:file:/home/ubuntu/.m2/repository/net/sourceforge/pmd/pmd/5.0.2/pmd-5.0.2.jar!/rulesets/java/imports.xml. 

所以看起来PMD忽略我的自定义规则集。

我想要自定义规则集工作。我究竟做错了什么?

回答

5

配置完行家-PMD-插件作为reporting

报告包含专门为站点生成阶段对应的元素。某些Maven插件可以生成在报告元素下定义和配置的报告。

这意味着你应该使用以下命令来执行: -

mvn clean site 

如果你想执行你提到,请在配置复制到builds,例如

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-pmd-plugin</artifactId> 
      <version>3.0</version> 
      <configuration> 
       <rulesets> 
        <ruleset>/home/ubuntu/ruleset.xml</ruleset> 
       </rulesets> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

然后,当你执行

mvn clean jxr:jxr pmd:check 

结果应该是作为你的预期。您可以进一步了解Maven Pom,here

我希望这可能有所帮助。

Regards,

Charlee Ch。

+2

谢谢。有用。我只是做了他们在[文档](http://maven.apache.org/plugins/maven-pmd-plugin/examples/usingRuleSets.html)中说的所有内容,并没有得到结果。关于将配置放置在“构建”部分中没有一句话。 – 2013-03-01 11:05:47

+0

但是,如果你看http://maven.apache.org/plugins/maven-pmd-plugin/usage.html,你会看到所有你可以把插件声明的地方...... – gavenkoa 2013-07-10 15:26:11

+0

与许多Maven插件一样,文件缺乏细节。我觉得这是令人困惑的,因为这是maven应该做的。 – 2017-09-13 16:46:40