PMD规则集未通过MAVEN下载/更新

时间:2016-06-18 07:25:09

标签: java maven pmd

我尝试将PMD集成到我的一个项目中(我正在使用MAVEN Build工具) 当我尝试集成时,我可以看到XML配置文件是必需的。 我试图下载PMD插件 - 我预计全局规则集文件可能在PMD插件中可用,但它们不是。 我用下面的链接: https://sourceforge.net/projects/pmd/?source=typ_redirect

谷歌搜索后,我看到了一个获取规则集的链接 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> 

2 个答案:

答案 0 :(得分:1)

如果您不需要使用自定义pmd规则集,则可以完全省略rulesets标记。

如果您只想使用某些pmd规则集,可以使用预定义规则集:

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

答案 1 :(得分:0)

您正在使用maven-pmd-plugin的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中看到可用的规则。