2016-06-18 64 views
0

我試圖將PMD集成到我的項目之一中(我正在使用MAVEN構建工具) 當我嘗試集成時,我可以看到XML配置文件是必需的。 我試圖下載PMD插件 - 我預計全局規則集文件可能在PMD插件中可用,但它們不是。 我用下面的鏈接: https://sourceforge.net/projects/pmd/?source=typ_redirectPMD規則集未通過MAVEN獲取下載/更新

谷歌搜索後,我已經看到了一個鏈接以獲取規則集 http://grepcode.com/file/repo1.maven.org/maven2/pmd/pmd/4.3 我不能下載所有XML文件。

是否有任何方式通過構建下載/更新,或者我們可以在任何位置獲得所有XML文件?我嘗試了我的級別,最好在谷歌搜索,無法弄清楚。

我在這裏附加了pom.xml。當PMD自動更新時,您能否讓我知道如何自動添加我的規則集?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.scm</groupId> 
    <artifactId>parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>pom</packaging> 
    <name>SCM-PRODUCT</name> 
    <description>SCM Product for learning purpose</description> 
    <properties> 
    <java.version>1.7</java.version> 
    <hibernate.validator.version>5.2.4.Final</hibernate.validator.version> 
    <javax.el-api.version>2.2.4</javax.el-api.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <checkstyle-config-url> 
     D:/rules/checkstyle/2.0/checkstyle-2.0.xml 
    </checkstyle-config-url> 
    <checkstyle.version>6.18</checkstyle.version> 

    <log4j.version>1.2.17</log4j.version> 
    <!-- TEST CASES RELATED BEGINS--> 

    <junit.version>4.12</junit.version>  

    <!-- TEST CASES RELATED ENDS HERE--> 

    <!-- STATIC CODE ANALYSIS PROPERTIES --> 
    <findbugs.plugin.version>3.0.3</findbugs.plugin.version> <!-- Reports on common code mistakes and pitfalls --> 
    <checkstyle.plugin.version>5.0</checkstyle.plugin.version> <!-- Checks Code Style for Developers --> 
    <pmd.plugin.version>3.6</pmd.plugin.version> <!-- Source Code Analyzer --> 

    <doxia.module.markdown.version>1.3</doxia.module.markdown.version> 
    <javadoc.plugin>2.8.1</javadoc.plugin> <!-- Generates JavaDoc --> 
    <jxr.plugin>2.3</jxr.plugin> <!-- Cross reference report of project source code --> 

    <!-- REPORTING TOOL PROPERTIES --> 
    <project.info.reports.plugin>2.4</project.info.reports.plugin> <!-- A plethora of miscellaneous report: info, ci, dependencies, scm, plugins, etc. --> 
    <site.plugin>3.1</site.plugin> 
    <sonar.plugin>3.2-RC3</sonar.plugin> <!-- Analysis and metrics on code over time --> 
    <surefire.plugin>2.12</surefire.plugin> <!-- Reports Test Results --> 
    <taglist.plugin>2.4</taglist.plugin> <!-- Reports on Tags such as @todo and //TODO --> 
    <versions.plugin>1.3.1</versions.plugin> 
    <maven-compiler-plugin>3.1</maven-compiler-plugin> 
    <cobertura.plugin>2.5.1</cobertura.plugin> <!-- Reports Test Coverage --> 

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    </properties> 
    <modules> 
    <module>services</module> 
    <module>presentation</module> 
    <module>service_validator</module> 
    <module>jsonvo</module> 
    </modules> 
    <dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-validator</artifactId> 
      <version>${hibernate.validator.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.el</groupId> 
      <artifactId>javax.el-api</artifactId> 
      <version>${javax.el-api.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.validation</groupId> 
      <artifactId>validation-api</artifactId> 
      <version>1.1.0.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>${junit.version}</version> 
      <scope>test</scope> 
     </dependency> 
     <!-- http://mvnrepository.com/artifact/log4j/log4j --> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>${log4j.version}</version> 
     </dependency> 
     <!-- http://mvnrepository.com/artifact/net.sourceforge.pmd/pmd --> 
     <dependency> 
      <groupId>net.sourceforge.pmd</groupId> 
      <artifactId>pmd</artifactId> 
      <version>5.4.2</version> 
     </dependency> 
    </dependencies> 
    </dependencyManagement> 
    <build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugin</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>${maven-compiler-plugin}</version> 
       <configuration> 
        <source>${java.version}</source> 
        <target>${java.version}</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-checkstyle-plugin</artifactId> 
       <version>2.17</version> 
       <configuration> 
        <includeTests>true</includeTests> 
        <rulesets> 
         <ruleset>${checkstyle-config-url}</ruleset> 
        </rulesets> 
        <minimumTokens>100</minimumTokens> 
        <targetJdk>${java.version}</targetJdk> 
        <failOnViolation>true</failOnViolation> 
       </configuration> 
       <executions> 
        <execution> 
        <phase>test</phase> 
        <goals> 
         <goal>check</goal> 
        </goals> 
       </execution> 
       </executions>  
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-pmd-plugin</artifactId> 
       <version>${pmd.plugin.version}</version> 
       <configuration> 
        <targetJdk>${java.version}</targetJdk> 
        <minimumTokens>20</minimumTokens> 
        <skipEmptyReport>false</skipEmptyReport> 
        <failOnViolation>true</failOnViolation> 
        <printFailingErrors>true</printFailingErrors> 
        <!--<includeTests>true</includeTests>--> 
        <rulesets> 
         <ruleset>${pom.basedir}/pmd-rulesets.xml</ruleset> 
        </rulesets> 
        <!-- 
        <excludeRoots> 
         <excludeRoot>target/generated-sources/antlr</excludeRoot> 
         <excludeRoot>target/generated-sources/antlr/com/puppycrawl/tools/checkstyle/grammars/javadoc</excludeRoot> 
        </excludeRoots> 
        --> 
       </configuration> 
       <executions> 
        <execution> 
         <goals> 
          <goal>pmd</goal> 
          <goal>cpd</goal> 
          <goal>cpd-check</goal> 
          <goal>check</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>findbugs-maven-plugin</artifactId> 
       <version>${findbugs.plugin.version}</version> 
       <configuration> 
        <effort>Max</effort> 
        <threshold>Low</threshold> 
        <excludeFilterFile>config/findbugs-exclude.xml</excludeFilterFile> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    <plugins> 

    </plugins> 
    </build> 
</project> 

回答

1

如果您不需要使用自定義pmd規則集,則可以完全省略rulesets標記。

如果你只想使用PMD規則集的部分,你可以使用預定義的:

 <rulesets> 
     <ruleset>/rulesets/java/braces.xml</ruleset> 
     <ruleset>/rulesets/java/naming.xml</ruleset> 
     </rulesets> 
0

您正在使用的maven-PMD-插件的3.6版本。規則集有一個默認值 - 它是java-basic,java-imports和java-unusedcode。請參閱maven-pmd-plugin documentation

如果您想從這些規則集開始,可以完全忽略rulesets標籤,如krzyk mentioned

Maven插件3.6使用PMD 5.3.5 - 所以下載PMD 4.3的規則集將不起作用。

但是,您不需要下載規則集。您可以創建your own custom ruleset,它引用了您希望在代碼中檢查的規則。這將是你的文件pmd-rulesets.xml

是否有任何方式通過構建下載/更新,或者我們可以在任何位置獲得所有XML 文件?

沒有這樣的規則集。啓用PMD提供的所有規則都沒有意義,因爲有些規則相互矛盾。請閱讀「最佳實踐」:Choose the rules that are right for you

您可以讓我知道如何自動添加我的規則集,每當PMD 自動更新?

你不需要添加你的規則集 - 你已經在使用它了。但是,如果新PMD版本有新規則,則不一定會激活這些新規則。因此,您可能需要閱讀PMD的發行說明,並檢查是否有新的有趣規則。然後,您可以引用規則集文件中的新規則。

對於java語言,您可以在Rulesets index中看到可用的規則。

相關問題