如何使maven-pmd-plugin支持最新的PMD版本? [英] How to make maven-pmd-plugin support the latest PMD release?

查看:229
本文介绍了如何使maven-pmd-plugin支持最新的PMD版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://maven.apache.org/plugins/maven-pmd- plugin/当前为2.4版,支持PMD 4.2.2版

http://maven.apache.org/plugins/maven-pmd-plugin/ is currently in version 2.4 which supports PMD version 4.2.2

是否可以通过此插件使用PMD 4.2.5版,如果可以,我们该怎么做?

Is it possible to use PMD version 4.2.5 with this plugin, if so how do we do this?

推荐答案

这是一个老问题,事情一直在发展,但是我面临着将maven-pmd-plugin:3.8从pmd 5.6.1升级到5.8.1的挑战. . maven-pmd-plugin页面在撰写本文时.

This is an old question and things have moved on, but I faced a challenge upgrading maven-pmd-plugin:3.8 from pmd 5.6.1 to 5.8.1. The documentation for doing this was missing from the maven-pmd-plugin page at the time of writing.

  1. 添加pmd-core,pmd-java和任何其他成熟的PMD工件作为插件依赖项.
  2. 如果您的规则包含在单独的.jar模块中,请将该模块也添加到依赖项中.
  3. 确保 check 目标是在 compile 阶段之后运行的- validate 太早了. (我选择了 process-test-classes 来在运行任何测试之前调用它,而不是通常的 verify 也可以,但稍后会运行它.)
  1. Add pmd-core, pmd-java and any other mavenized PMD artifacts as plugin dependencies.
  2. If your rules are contained within in a separate .jar module, add that module to the dependencies also.
  3. Ensure that the check goal is run after the compile phase - validate is too soon. (I picked process-test-classes to invoke it just before any tests are run rather than the more usual verify which is also OK but will run it later).

pom.xml配置:

pom.xml configuration:

<properties>
    <rev.javac>1.8</rev.javac>
    <rev.pmd-plugin>3.8</rev.pmd-plugin>
    <rev.pmd>5.8.1</rev.pmd>
</properties>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>${rev.pmd-plugin}</version>
    <dependencies>
        <dependency>
            <groupId>my.project.group</groupId>
            <artifactId>project-standards</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.pmd</groupId>
            <artifactId>pmd-core</artifactId>
            <version>${rev.pmd}</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.pmd</groupId>
            <artifactId>pmd-java</artifactId>
            <version>${rev.pmd}</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>pmd-validation</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <rulesets>
            <ruleset>/pmd/project-pmd-rules.xml</ruleset>
        </rulesets>
        <targetDirectory>${project.build.directory}</targetDirectory>
        <targetJdk>${rev.javac}</targetJdk>
        <failOnViolation>true</failOnViolation>
        <failurePriority>5</failurePriority>
        <verbose>false</verbose>
        <linkXRef>false</linkXRef>
    </configuration>
</plugin>

这篇关于如何使maven-pmd-plugin支持最新的PMD版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆