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
.
Note that Checkstyle will run with the same Java version used to run Gradle.
The Checkstyle plugin adds the following tasks to the project:
checkstyleMain
— Checkstyle-
Depends on:
classes
Runs Checkstyle against the production Java source files.
checkstyleTest
— Checkstyle-
Depends on:
testClasses
Runs Checkstyle against the test Java source files.
checkstyleSourceSet
— Checkstyle-
Depends on:
sourceSetClasses
Runs Checkstyle against the given source set’s Java source files.
By default, the Checkstyle plugin expects configuration files to be placed in the root project, but this can be changed.
<root> └── config └── checkstyle // (1) └── checkstyle.xml // (2) └── suppressions.xml
-
Checkstyle configuration files go here
-
Primary Checkstyle configuration file
The Checkstyle plugin adds the following dependency configurations:
Name | Meaning |
---|---|
|
The Checkstyle libraries to use |
See the CheckstyleExtension class in the API documentation.
The Checkstyle plugin defines a config_loc
property that can be used in Checkstyle configuration files to define paths to other configuration files like suppressions.xml
.
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: