checkstyle ANT Task

Description

This task runs checkstyle over specified Java files. The task has been tested using ANT 1.3. The latest version of checkstyle can be found at http://www.puppycrawl.com/checkstyle. This task is included in the checkstyle distribution.

Installation

The easiest way is to include checkstyle-all-1.3.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:

  1. checkstyle-1.3.jar
  2. ANTLR 2.7.1 classes. antlr.jar is included in the distribution.
  3. Jakarta Regexp 1.2 classes. jakarta-regexp-1.2.jar is included in the distribution.

To use the task in a build file, you will need the following taskdef declaration:

  <taskdef name="checkstyle"
           classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"/>

Parameters

Attribute Description Required
file File to run checkstyle on. One of either file or at least one nested fileset element
allowTabs Indicates whether to allow tabs. Defaults to "false". No
allowProtected Indicates whether to allow protected data. Defaults to "false". No
allowNoAuthor Indicates whether to allow no @author tag to be defined for class and interface Javadoc comments. Defaults to "false". No
maxLineLen Specifies the maximum line length. Default value is defined here. No
ignoreImportLen Specifies whether to ignore the maximum line length for import statements. Defaults to "false". No
maxMethodLen Specifies the maximum method length. Default value is defined here. No
maxConstructorLen Specifies the maximum constructor length. Default value is defined here. No
maxFileLen Specifies the maximum file length. Default value is defined here. No
memberPattern Specifies the regular expression to match against member variables. Default value is defined here. No
publicMemberPattern Specifies the regular expression to match against public member variables. Default value is defined here. No
paramPattern Specifies the regular expression to match against parameters. Default value is defined here. No
constPattern Specifies the regular expression to match against static/final variables. Default value is defined here. No
staticPattern Specifies the regular expression to match against static variables. Default value is defined here. No
typePattern Specifies the regular expression to match against type names. Default value is defined here. No
headerFile Specifies the file containing the header lines. Default is to not check. No
headerIgnoreLine Specifies the line in the header to ignore when comparing. Default it to not ignore any line. No
relaxJavadoc Specifies whether to relax checking Javadoc comments. Defaults to "false". No
ignoreJavadoc Specifies whether to completely ignore checking Javadoc comments. Defaults to "false". No
ignoreImports Specifies whether to ignore checking import statements. Defaults to "false". No
ignoreWhitespace Specifies whether to ignore checking whitespace. Defaults to "false". No
ignoreBraces Specifies whether to ignore checking braces. Defaults to "false". No
failOnViolation Specifies whether the build will continue even if there are violations. Defaults to "true". No
cacheFile Specifies the name of a file that can be used to cache details of files that pass checkstyle. This can signicantly increase the speed of checkstyle on successive runs. No

Examples

Run checkstyle on a single file

  <checkstyle file="Check.java"/>

Run checkstyle on a set of Java files in directory

  <checkstyle>
    <fileset dir="src/checkstyle" includes="**/*.java"/>
  </checkstyle>

Run checkstyle on a set of Java files and allow tabs

  <checkstyle allowTabs="yes">
    <fileset dir="src/checkstyle" includes="**/*.java"/>
  </checkstyle>

Run checkstyle on a set of Java files and disable pattern matching

  <checkstyle allowTabs="yes"
              paramPattern="."
              constPattern="."
              staticPattern="."
              memberPattern=".">
    <fileset dir="src/checkstyle" includes="**/*.java"/>
  </checkstyle>

Copyright © 2001 Oliver Burn. All rights Reserved.