2016-06-18 32 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中看到可用的规则。

相关问题