Skip to content

Latest commit

 

History

245 Commits

Folders and files

Repository files navigation

Checkstyle Extension for bld

License Java bld Release Snapshot GitHub CI

To install the latest version, add the following to the lib/bld/bld-wrapper.properties file:

bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyle

For more information, please refer to the extensions documentation.

Check Source Code with Checkstyle

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 checkstyle

Checkstyle Version

The 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)));

Source Directories

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();

Output Format and File

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();

Excluding Files and Directories

new CheckstyleOperation()
        .fromProject(this)
        .configurationFile("config/sun_checks.xml")
        .exclude("src/main/java/generated")
        .excludeRegex(".*Generated\\.java$")
        .execute();

Inspecting a Single File's AST

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();

Dependency Repository

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();

API Reference

Please check the CheckstyleOperation documentation for all available configuration options.

Releases

Packages

Used by

Contributors

Languages