You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

You want to check your Java code with PMD and Checkstyle.

You know what to do, you set up some rules files.

You build with maven 2.

You know what to do, you set up the plugins.

You type at Eclipse.

Now you have trouble. You need:

a) Your Eclipse code formatting style, warning, and cleanup to be consistent with your rules.
b) Eclipse configuration for the Eclipse plugins for PMD and Checkstyle that are consistent with
your rules.

If you start looking at this, you will get a headache.

Luckily for you, Dan Kulp did a ton of work to make this work. You can see it in CXF, and adapt it
to your own purposes.

If you've done much Eclipse configuration, you know that pathnames are a pain. Relative pathnames
can't cross Eclipse projects. Anything you can wire up via classpath is easier than anything
wired by pathname. Thus the following scheme.

Step 1: A project to contain the common files.

CXF has a 'cxf-buildtools' project. It contains files for the tools. For each tool, there
are two files: the XML file that configures the tool (name ends with .xml), and the more-or-less
XML file that Eclipse knows how to read to configure the Eclipse plugin. These files all live
in src/main/resources. When the builttools project builds, it just copies them to target
and bundles them into a JAR file.

Step 2: Maven plugins use the files.

The Maven plugins, of course, feed the same core XML files to the tools. By making the buildtools artifact
a dependency of the Maven checkstyle and PMD plugins, the files become available by classpath.
This happens in the parent POM (parent/pom.xml) so that it is set up for all of the projects.

Step 3: Eclipse

Eclipse is configured via a collection of files that live in the
.settings directories of the workspace and the individual
projects. Each plugin defines the format of its settings. None of them
are documented: it's all reverse engineering.

In the top level POM, there is a profile called 'setup.eclipse'. It
uses a combination of ant, xslt, and the 'copy' task to create all of the desired settings files.
Some of them are created by copying or modifying templates in etc/eclipse.

Eventually, setup.eclipse runs the Maven eclipse:eclipse goal to do the vanilla work
of creating .classpath and .project files for each of the projects.

  • No labels