Eclipse setup for Checkstyle and PMD

You can cofigure Eclipse to use the same Checkstyle and PMD rules that are used during the maven build and mark code that breaks these rules in the IDE. First off you need to install the Eclipse Checkstyle and Eclipse PMD plugins as outlined on the download links and afterwards restart Eclipse.

Next, you must configure Checkstyle and PMD plugins to use the same rule sets as maven. To do this, open the Eclipse preferences dialog (Window -> Preferences)
Checkstyle:

  • Go to the Checkstyle preferences and click "New..." beside the grid of Global Check Configurations to add a new Checkstyle rule.
  • Select "External Configuration File" give it a name (e.g. "FUSE Management Rules")
  • Point the location to <checkoutdir>/codestyle/src/main/resources/checkstyle.xml
  • In the Global Check Configs grid, select the new config and click "Set as Default"
  • You may also want to tick "Include rule names in violation messages". I find it quite useful.

PMD:

  • Expand the PMD preferences and go to "Rules configuration".
  • Remove all existing rules by clicking "Clear all".
  • Click "Import rule set" and select <checkoutdir>/codestyle/src/main/resources/pmd-ruleset.xml

After doing all this, Checkstyle will be enabled by default for all projects (you can disable it in the project properties).

PMD on the other hand is disabled for all projects by default so you have to explicitly enable it in all projects in the project properties:

Right-click on a project, select properties and go to the Checkstyle or PMD section and enable/disable Checkstyle/PMD as you wish.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jun 02, 2009

    Dan Kulp says:

    If you take a look at CXF's poms, you CAN get "mvn eclipse:eclipse" to setup PM...


    If you take a look at CXF's poms, you CAN get "mvn eclipse:eclipse" to setup PMD and Checkstyle for the projects. Might be worth investigating.