5

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?

Joe
  • 14,513
  • 28
  • 82
  • 144

2 Answers2

3

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.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • I am in the process of trying your suggestions, but I need support for JDK 1.5 (pmd-jdk14 makes it JDK 1.4 compliant) Making the above changes caused the plugin to retrive the newer version of the PMD, but it still kept generating a PMD 4.2.2 report. I am not sure why this is happening, but will keep you posted on the results. – Joe Jan 11 '10 at 11:47
  • I did some testing on my side and it seems indeed that specifying `dependencies` for the plugin under `build` doesn't affect the `reporting` section. However, it's not possible to specify dependencies under `reporting` so I actually don't know how to solve this (except by patching the maven-pmd-plugin). – Pascal Thivent Jan 11 '10 at 22:52
  • Yes, reporting section doesn't allow you to specify dependencies. I kind of moved this configuration inside build-->pluginManagement-->plugins-->plugin, but I am verifying to see if I can get this working as part of the build phase – Joe Jan 12 '10 at 04:43
  • I am unable to get this working with the suggestion mentioned above, it still seems to generate only a PMD 4.2.2 report – Joe Jan 25 '10 at 04:03
  • If the build fails with error that some method is missing, check https://stackoverflow.com/questions/61417986/pmd-plugin-fails-with-java-14-unsupported-targetjdk/61418174#61418174 – Yan Khonski Apr 24 '20 at 22:07
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>
Ed Randall
  • 6,887
  • 2
  • 50
  • 45