2013-02-28 40 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

相關問題