This task runs checkstyle over specified Java files. The task has been tested using ANT 1.4.1. The latest version of checkstyle can be found at http://checkstyle.sourceforge.net/. This task is included in the checkstyle distribution.
The easiest way is to include checkstyle-all-1.4.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:
To use the task in a build file, you will need the following taskdef declaration:
<taskdef name="checkstyle"
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"/>
| 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 |
| javadocScope | Specifies the visibility scope where javadoc comments are checked. Valid values are "nothing", "public", "protected", "package", "private" and "anoninner". Defaults to "private". | No |
| ignoreImports | Specifies whether to ignore checking import statements. Defaults to "false". | No |
| ignoreWhitespace | Specifies whether to ignore checking whitespace. Defaults to "false". | No |
| ignoreCastWhitespace | Specifies whether to ignore checking for whitespace after a cast. 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 |
Older versions of the checkstyle task supported the boolean parameters relaxJavadoc and ignoreJavadoc. These parameters have been removed because they were conflicting and the semantics of relaxJavadoc was not clearly specified. The two parameters have been replaced by the javadocScope parameter. Instead of ignoreJavadoc="true" you can now use javadocScope="nothing". The behaviour of relaxJavadoc="true" is roughly the same as javadocScope="protected".
This task supports the nested elements <fileset> and <formatter>. The parameters for the <formatter> element are:
| Attribute | Description | Required |
| type |
The type of output to generate. The valid values are:
Defaults to "plain". |
No |
| toFile | The file to write output to. Defaults to standard output. Note, there is no way to explicitly specify standard output. | No |
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 files and output messages to standard output in plain format, and a file in XML format
<checkstyle>
<fileset dir="src/checkstyle" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="xml" toFile="build/checkstyle_errors.xml"/>
</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.