How to make maven-pmd-plugin support the latest PMD release?

房东的猫 提交于 2020-05-15 04:30:25

问题


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

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


回答1:


There is a Jira Issue for this, see MPMD-97 (I suggest to vote for it).

For now, you can try to upgrade locally the pmd version used in the plugin with:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>2.4</version>

        <dependencies>

          <dependency>
              <groupId>pmd</groupId>
              <artifactId>pmd-jdk14</artifactId>
              <version>4.2.5</version>
          </dependency>

        </dependencies>
      </plugin>
    </plugins>
  </build>

I didn't test this, I don't know if it'll work seamlessly.




回答2:


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. 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 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>


来源:https://stackoverflow.com/questions/2033217/how-to-make-maven-pmd-plugin-support-the-latest-pmd-release

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!