Overview

This project provides PMD rules to be used in smartics projects.

Integration with Maven

Please use the maven-pmd-plugin to use the rules from within Maven.

The following snippet shows how the rules can be integrated into the project.

<build>
  <plugins>
    <plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.0.1</version>
        <dependencies>
          <dependency>
            <groupId>de.smartics.config</groupId>
            <artifactId>config-smartics-pmd</artifactId>
            <version>2.0.0</version>
          </dependency>
        </dependencies>
      </plugin>
  ...
  </plugins>
</build>

...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-pmd-plugin</artifactId>
      <version>3.0.1</version>
      <configuration>
        <linkXref>true</linkXref>
        <sourceEncoding>UTF-8</sourceEncoding>
        <minimumTokens>100</minimumTokens>
        <targetJdk>1.5</targetJdk>
        <verbose>true</verbose>
          <ruleset>houserules.xml</ruleset>
        </rulesets>
      </configuration>
    </plugin>
    ...

Since configuration information is passed from the report to the build plugin, but other information not (or not necessarily), to sync the version information you may want to specify it as a property and reference to it from the version element.

<version>${maven-pmd-plugin.version}</version>
...
  <properties>
    <maven-pmd-plugin.version>3.0.1</maven-pmd-plugin.version>
  </properties>

Integration with eclipse

Please configure the maven-eclipse-plugin to use the rules from within your eclipse IDE.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-eclipse-plugin</artifactId>
  <version>2.6</version>
  <configuration>
    <additionalConfig>
      <file>
        <name>.pmd</name>
        <location>/eclipse-pmd.xml</location>
      </file>
      <file>
        <name>.ruleset</name>
        <location>/houserules.xml</location>
      </file>
    </additionalConfig>
    <additionalBuildcommands>
      <buildCommand>
        <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
        <arguments></arguments>
      </buildCommand>
    </additionalBuildcommands>
    <additionalProjectnatures>
      <projectnature>net.sourceforge.pmd.eclipse.plugin.pmdNature</projectnature>
    </additionalProjectnatures>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>de.smartics.config</groupId>
      <artifactId>config-smartics-pmd</artifactId>
      <version>2.0.0</version>
    </dependency>
  </dependencies>
</plugin>

The contents of the eclipse-pmd.xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<pmd>
  <useProjectRuleSet>true</useProjectRuleSet>
  <ruleSetFile>.ruleset</ruleSetFile>
  <includeDerivedFiles>false</includeDerivedFiles>
  <violationsAsErrors>true</violationsAsErrors>
</pmd>

To update the eclipse project information use the maven-eclipse-plugin:

mvn eclipse:eclipse

Unfortunately the PMD configuration does not get activated automatically. After running Maven please open the project properties (context menu on the project and select "Properties"), select the "PMD" topic and then select the checkboxes for:

  1. "Enable PMD"
  2. "Use the ruleset configured in a project file" (".ruleset" is already entered in the textfield next to it)
The PMD configuration dialog.