------ Customizing the Maven 2 Checkstyle Plugin ------ Customizing the Maven 2 Checkstyle Plugin * Use a custom Checkstyle checker configuration. A custom {{{http://checkstyle.sourceforge.net/config.html#Checker}Checker configuration xml file}} can be defined and then referenced via a URL, File, or build classpath resource reference. To reference the a custom Checkstyle Checker configuration, use the <> parameter. ------------------- ... org.apache.maven.plugins maven-checkstyle-plugin checkstyle.xml ... ------------------- This example causes the Maven 2 Checkstyle plugin to check for a File named <> or a resource named <> within the compile scope of the dependencies or build extensions classpath. There are 4 predefined Checkstyle configuration definitions that ship with the Maven 2 Checkstyle Plugin, the Sun Microsystems Definition is selected by default. * <> - Sun Microsystems Definition (default). * <> - Maven Development Definitions. * <> - Turbine Development Definitions. * <> - Avalon Development Definitions. * Use custom Checkstyle property expansion definitions. A custom {{{http://checkstyle.sourceforge.net/config.html#Properties}property expansion definitions}} for the Checker can be defined. Checkstyle uses the property expansion mechanism to allow injection of specific values into a pre-defined Checker configuration. Using property expansion alone is an insufficient means to customize the checks performed by Checkstyle. Example: <> - only checks the package name in use to ensure that it conforms to the desired scheme, but allows for users of this Checker to specify their own projectname. ------------------- ------------------- Example: <> - Specifies the <> property expansion that Checkstyle will use when encountering such a variable in the above Checker configuration. ------------------- ... org.apache.maven.plugins maven-checkstyle-plugin checkstyle.xml projectname=whizbang ... ------------------- The property expansion information can also come from a location using the <> parameter, which can point to a URL, File, or build classpath resource reference. * Using a Suppressions filter. Checkstyle allows the definition of a list of files and their line ranges that should be suppressed from reporting any violations (known as a {{{http://checkstyle.sourceforge.net/config.html#Filters}supressions filter}} ). Example: <> ------------------- ------------------- Example: <> - Specifies the suppressions filter that Checkstyle should use. ------------------- ... org.apache.maven.plugins maven-checkstyle-plugin checkstyle.xml checkstyle-suppressions.xml ... ------------------- * Use a custom developed Checkstyle Check modules. For the really adventurous, custom Checkstyle checks can be used with the Maven 2 Checkstyle Plugin. The plugin provides the ability to define the {{{http://checkstyle.sourceforge.net/config.html#Packages}package names definition}} required to reference your custom check modules. TIP: Create a maven project that produces a jar file of your custom checks, and then include it in your projects using the maven build extension in the pom.xml to avoid them being included in the compile or package phases of your project. Example: <>. ------------------- $ jar -tvf mycompany-checkstyle-checks-1.0.jar 0 Tue Nov 29 13:13:14 EST 2005 META-INF/ 401 Tue Nov 29 13:13:12 EST 2005 META-INF/MANIFEST.MF 0 Tue Nov 29 13:13:12 EST 2005 META-INF/maven/ 0 Tue Nov 29 13:13:14 EST 2005 META-INF/maven/com.mycompany/ 0 Tue Nov 29 13:13:14 EST 2005 META-INF/maven/com.mycompany/mycompany-checkstyle-checks/ 8489 Tue Nov 29 13:13:14 EST 2005 META-INF/maven/com.mycompany/mycompany-checkstyle-checks/pom.xml 151 Tue Nov 29 13:13:14 EST 2005 META-INF/maven/com.mycompany/mycompany-checkstyle-checks/pom.properties 0 Tue Nov 29 13:13:14 EST 2005 com/ 0 Tue Nov 29 13:13:14 EST 2005 com/mycompany/ 0 Tue Nov 29 13:13:14 EST 2005 com/mycompany/checkstyle/ 1252 Tue Nov 29 13:13:14 EST 2005 com/mycompany/checkstyle/packagenames.xml 12939 Tue Nov 29 13:13:14 EST 2005 com/mycompany/checkstyle/PurityCheck.class ------------------- Example: <> ------------------- ------------------- Example: <> ------------------- ... org.apache.maven.plugins maven-checkstyle-plugin checkstyle.xml com/mycompany/checkstyle/packagenames.xml ... com.mycompany mycompany-checkstyle-checks 1.0 -------------------