Checkstyle Extension for bld
To install the latest version, add the following to the
lib/bld/bld-wrapper.properties file:
bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyleFor more information, please refer to the extensions documentation.
To check your code with Checkstyle, include the following in your build file:
@BuildCommand(summary = "Check code style")
public void checkstyle() throws Exception {
new CheckstyleOperation()
.fromProject(this)
.configurationFile("config/sun_checks.xml")
.execute();
}./bld checkstyleThe Checkstyle dependency is resolved automatically by the extension.
By default, the extension downloads the version defined by the
CHECKSTYLE_VERSION
constant.
To pin a specific release, use the
version
method:
new CheckstyleOperation()
.fromProject(this)
.configurationFile("config/sun_checks.xml")
.version("14.4.0")
.execute();If your build file still declares a Checkstyle test dependency from an earlier
version of the extension, it can now be safely removed:
// No longer required — Checkstyle is resolved by the extension itself.
// scope(test)
// .include(dependency("com.puppycrawl.tools", "checkstyle", version(14, 4, 0)));fromProject(this)
defaults the source directories to the project's src/main/java and
src/test/java. Use
sourceDir(...)
to override them:
new CheckstyleOperation()
.fromProject(this)
.configurationFile("config/sun_checks.xml")
.sourceDir("src/main/java") // main only, tests skipped
.execute();By default, results are printed to stdout in plain text. Use
format(...)
for machine-readable output and
outputPath(...)
to write to a file:
new CheckstyleOperation()
.fromProject(this)
.configurationFile("config/sun_checks.xml")
.format(OutputFormat.XML)
.outputPath("build/reports/checkstyle.xml")
.execute();new CheckstyleOperation()
.fromProject(this)
.configurationFile("config/sun_checks.xml")
.exclude("src/main/java/generated")
.excludeRegex(".*Generated\\.java$")
.execute();The AST inspection options (see the API reference for the full list) operate on
exactly one file. Point
sourceDir(...)
at that file:
new CheckstyleOperation()
.fromProject(this)
.sourceDir("src/main/java/com/example/Foo.java")
.treeWithComments(true)
.execute();Checkstyle is resolved from Maven Central by default. To use a different repository, for example Google's mirror:
new CheckstyleOperation()
.fromProject(this)
.configurationFile("config/sun_checks.xml")
.repository(Repository.GOOGLE_MAVEN_CENTRAL)
.execute();Please check the CheckstyleOperation documentation for all available configuration options.