Using Custom Checkstyle Checks

With Checkstyle it is possible to create own checks and make them available to Checkstyle. This Chapter explains how to configure Checkclipse to use this custom checks and how to build the jars with custom checks, so they perfectly fit to Checkclipse.

Making the checks known to Checkclipse

There are three different ways to make custom checks known to Checkclipse. They will be explained in the following sections.

The Project Level

On the properties page of the project you can add one or more custom jars in the field "Jar Files with additional checkstyle checks". Just hit the Add button and select the jar you want to add. The jar must be located somewhere in the workspace.

This is expecially useful, if you created a check that is specific for the current project or if you want to distribute the source of your project.



Using a Plug-In Fragment

You can make your custom checks known to checkstyle using a Plug-In Fragment. See here for documentation.


Global level 1

The plugin directory contains a subdirectory named "extension-lib". Jar files placed in this directory are automatically picked up at runtime and the contained checks are available to Checkstyle. The plugin directory is located at Eclipse Install Directory /plugin/de.mvmsoft.checkclipse_2.0.0 (with the appropriate version number).



Global level 2

It is possible to write a custom check that doesn't work if the jar is configured in one of the above ways. This is namly if the check replicates the original package structure of Checkstyle to get access to package local classes or methods. In this cases Checkclipse will report, that an IllegalAccessError has occured during checking. Then the jar with the custom Checks has to be added to the plugins classpath directly.

  1. Stop eclipse

  2. Change to the plugin directory Eclipse Install Directory/plugin/de.mvmsoft.checkclipse_2.0.0 .

  3. Place the jar file with your check in the subdirectory lib .

  4. Edit the file plugin.xml to add your jar to the plug-ins classpath:

    <?xml version="1.0" encoding="UTF-8"?> 
    <?eclipse version="3.0"?> 
      name="Checkclipse Style Checker" 
      provider-name="Marco van Meegen" 
        <library name="checkclipse.jar"/> 
        <library name="lib/checkstyle-all-Version.jar" /> 
        <library name="lib/checkstyle-optional-Version.jar" /> 
        <library name="lib/myChecks.jar">
  5. Restart Eclipse. You might need to use the command line parameter -clean , so that Eclipse is forced to pick up the changed plugin.xml file.