Table of Contents
The Checkstyle plugin performs quality checks on your project's Java source files using Checkstyle and generates reports from these checks.
To use the Checkstyle plugin, include the following in your build script:
The plugin adds a number of tasks to the project that perform the quality checks. You can execute the checks by running gradle check.
The Checkstyle plugin adds the following tasks to the project:
Table 56.1. Checkstyle plugin - tasks
| Task name | Depends on | Type | Description |
checkstyleMain
|
classes |
Checkstyle |
Runs Checkstyle against the production Java source files. |
checkstyleTest
|
testClasses |
Checkstyle |
Runs Checkstyle against the test Java source files. |
checkstyle
|
|
Checkstyle |
Runs Checkstyle against the given source set's Java source files. |
The Checkstyle plugin adds the following dependencies to tasks defined by the Java plugin.
Table 56.2. Checkstyle plugin - additional task dependencies
| Task name | Depends on |
check |
All Checkstyle tasks, including checkstyleMain and checkstyleTest. |
The Checkstyle plugin expects the following project layout:
Table 56.3. Checkstyle plugin - project layout
| File | Meaning |
config/checkstyle/checkstyle.xml
|
Checkstyle configuration file |
The Checkstyle plugin adds the following dependency configurations:
Table 56.4. Checkstyle plugin - dependency configurations
| Name | Meaning |
checkstyle
|
The Checkstyle libraries to use |
See the CheckstyleExtension class in the API documentation.
The HTML report generated by the Checkstyle task
can be customized using a XSLT stylesheet, for example to highlight specific errors or change its
appearance:
Example 56.2. Customizing the HTML report
build.gradle
tasks.withType(Checkstyle) {
reports {
xml.enabled false
html.enabled true
html.stylesheet resources.text.fromFile('config/xsl/checkstyle-custom.xsl')
}
}