CLI tool
checkstyle/checkstyle avatar
checkstyle/checkstyle

Checkstyle: enforcing a Java coding standard from the command line, Maven and Gradle

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.

9,579 stars4,256 forksJavaLGPL-2.1

At a glance

What is it?
Checkstyle parses Java source and reports style violations against a configurable rule set. It ships Google Java Style and Sun Code Conventions defaults, runs as a jar, and integrates through Maven or Gradle plugins. The trade-off is that its own configuration is a project you have to maintain.
Who is it for?
Adopt Checkstyle if your team already has a written Java style standard and wants the build to enforce it, or if you are willing to adopt the Google or Sun conventions as-is and take the supplied config as a starting point. Do not adopt it as a formatter or as a substitute for a compiler-integrated analyzer; it will not rewrite your files and it cannot see types.
Can I use it commercially?
Yes, with conditions. LGPL-2.1 is a weak copyleft licence: you can use it inside commercial and closed-source software, but if you distribute changes to its own files, you must publish those changes under the same licence.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Java, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 29, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What Checkstyle actually checks, and who ends up using it

Checkstyle reads Java source files and reports where they deviate from a declared standard. The README describes it plainly: "Checkstyle is a tool that ensures adherence to a code standard or a set of best practices." The defaults are the Google Java Style Guide and the Sun Code Conventions, but the tool is driven entirely by an XML configuration file that names individual modules. A module such as FallThrough detects one specific pattern, in that case a switch branch that falls into the next one without a break. There is no bundled black-box rule engine you cannot inspect; every rule that fires is named in the config.

That design points at the audience. If your team has already agreed on an indentation width, an import order, or a ban on empty catch blocks, Checkstyle is the mechanism that turns the agreement into a build failure. It suits Java shops with a written style document, or teams that want to adopt a published one wholesale. It is a poor fit for a codebase in another language, and it is not a correctness checker: it does not resolve types across your dependency graph the way a compiler-based analyzer does, so rules that need semantic information are either absent or approximate.

The config file is the architecture

Everything runs through one XML document. The root element is a module named Checker, and inside it you nest other modules. TreeWalker is the module that walks the parsed syntax tree, so most checks live under it. The README's example puts FallThrough inside TreeWalker inside Checker, and that nesting is not cosmetic: modules placed at the Checker level operate on files and lines, while modules inside TreeWalker operate on individual AST nodes.

The pipeline is short. Checkstyle parses each Java file with ANTLR, which the README lists among the libraries it uses, builds a tree, then dispatches each node to the modules registered for that node type. A module reports a violation with a line, a column, a message and its own name, and the run ends with a count. Configuration properties can be set per module, and the DTD referenced in the config file defines which attributes are legal, so a typo in an attribute name is caught when the config is loaded rather than silently ignored. That is the part worth appreciating: the config is validated against a schema, and the error message points at the offending element.

Installing Checkstyle and running a first audit

The README gives two ways in: download the latest release from GitHub, or add Checkstyle to your build from Maven Central under the artifact com.puppycrawl.tools. There is no installer and no daemon. The command line program takes a config file and one or more source files.

The README's quick start writes a minimal config that enables a single check, then runs the jar against a test file. The config below is that example: one module, FallThrough, nested under TreeWalker under Checker.

bash
$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="FallThrough"/>
  </module>
</module>

With the config in place, the README invokes the all-in-one jar with -c for the config and the source file as the argument. Note that the jar filename in the README carries a version number, so the name you type depends on the release you downloaded.

bash
$ java -jar checkstyle-10.18.1-all.jar -c config.xml Test.java
Starting audit...
[ERROR] Test.java:9:9: Fall through from previous branch of switch statement [FallThrough]
Audit done.
Checkstyle ends with 1 errors.

What you should see is a line per violation in the form file:line:column, the message, and the module name in brackets, followed by a final count. Exit status is the thing to wire into CI, and the README does not spell out the exit codes; check the command line documentation at checkstyle.org/cmdline.html before you assume a particular value means a particular outcome.

Maven and Gradle: where Checkstyle usually lives

Running the jar by hand is for trying rules out. In a real build the tool is invoked by a plugin. The README points at Maven Central under the group and artifact com.puppycrawl.tools:checkstyle, and the repository's own build is a Maven project, so the parent pom is the reference for how the project wires itself up. Maven users bind the check goal to a lifecycle phase so a violation fails the build; Gradle users apply the checkstyle plugin and point it at a config file. The related searches around checkstyle maven plugin and checkstyle gradle plugin reflect that this is how most people meet the tool.

The important consequence of plugin integration is that the config file becomes a build artifact. It needs a home in the repository, a version, and a review process. Teams that treat it as an afterthought end up with a config that nobody understands and a build that fails for reasons no one can explain. If you are choosing between a plugin and the raw jar, the plugin buys you incremental execution and reporting; the jar buys you nothing but a clean, dependency-free way to test a rule before you commit it.

Where Checkstyle stops being the right tool

Checkstyle works on syntax and on a limited amount of structure. It is not a type checker and it does not compile your code, so anything that requires knowing what a name refers to is out of reach. A rule about unused private methods, for instance, depends on information the syntax tree alone does not carry. If your team's real problem is null-safety or resource leaks, a compiler-integrated analyzer is the correct instrument, and Checkstyle will only ever approximate it.

The second limitation is the config itself. A mature Checkstyle setup is a few hundred lines of XML that someone has to own. Suppression files, per-module properties, and the interaction between TreeWalker-level and Checker-level modules all add surface area. When the config drifts from the style document it claims to encode, the tool keeps passing builds that violate the standard, and nobody notices until a new hire asks why the rule is not firing. There is no built-in mechanism in the README's description that reconciles the two. That is a documentation and process problem, not a defect, but it is the failure mode that shows up most often.

Third, the README does not document rollback or migration between config versions. If you upgrade Checkstyle and the DTD version changes, the README is silent on what that means for an existing config.xml. Treat version upgrades as a change that needs its own testing pass.

Checkstyle versus Spotless

The comparison people search for is checkstyle vs spotless, and the difference is one of intent rather than features. Checkstyle reports violations and leaves the fix to you. Spotless is built around applying formatters so the file is rewritten into the desired shape. A Checkstyle run on a badly formatted file produces a list; a Spotless run produces a diff.

That distinction decides which one belongs in your pipeline. If the standard is a matter of formatting alone (spacing, line wrapping, import order), an auto-formatter removes the argument entirely and the review comment about indentation never gets written. If the standard includes things a formatter will not touch, such as requiring Javadoc on public methods or banning a particular construct, you need a checker. Plenty of teams run both: the formatter handles what can be mechanical, and Checkstyle enforces what cannot. The mistake is adopting Checkstyle to solve a formatting dispute, because you will spend the next year adding rules that a formatter would have applied for free.

Licence, releases and what an upgrade costs

Checkstyle is licensed under the GNU LGPL v2.1, and the repository also carries a LICENSE.apache20 file, which reflects the mixed provenance of a long-lived project rather than a dual-licence grant for the tool itself. LGPL matters mainly if you redistribute the library or link against it in a way that triggers the licence's relinking obligations; running the command line jar or the Maven plugin in your build does not change your application's licence. That is a summary of what the repository states, not legal advice, and any distribution decision should go past whoever handles licensing at your organisation.

On cadence, the repository is active: the last push was on 2026-09-21, and recent releases include checkstyle-14.1.0 on 2026-08-30, checkstyle-14.0.0 on 2026-08-18 and checkstyle-13.11.0 on 2026-08-16. Frequent releases mean frequent rule additions and occasional behaviour changes, and the upgrade cost is not the dependency bump. It is re-running the build against the new version and reading the diff in violations, because a new release can add checks or tighten existing ones. Pin the version in your build file and upgrade deliberately rather than tracking the latest.

Editorial conclusion

Adopt Checkstyle if your team already has a written Java style standard and wants the build to enforce it, or if you are willing to adopt the Google or Sun conventions as-is and take the supplied config as a starting point. Do not adopt it as a formatter or as a substitute for a compiler-integrated analyzer; it will not rewrite your files and it cannot see types. Before committing, verify three things: that the config file you intend to use loads against the DTD it declares, what exit status your build will see on a violation, and how the checkstyle version you pin behaves on your existing source, since a new release can add checks that fail a previously green build.

Frequently asked questions

How do I run Checkstyle from the command line?

Download the latest release from GitHub or take it from Maven Central, then invoke the all-in-one jar with -c pointing at your config XML and the Java file as the argument. The README's example uses java -jar checkstyle-10.18.1-all.jar -c config.xml Test.java and prints one line per violation followed by a final error count.

How can I use Checkstyle in Maven?

Add Checkstyle to your build from Maven Central under the artifact com.puppycrawl.tools:checkstyle, then invoke it through the Maven plugin so violations fail the build. The README itself only points at Maven Central and the usage documentation at checkstyle.org/cmdline.html; the plugin configuration details live in that documentation, not in the README.

How do I use Checkstyle in Gradle?

Apply the Gradle checkstyle plugin and point it at a config file, the same XML format the command line program consumes. The README does not walk through the Gradle setup, so the plugin's own documentation is the place to confirm the task names and config properties.

How do I use Checkstyle in Visual Studio Code?

The README and the repository material do not describe a VS Code integration, so there is nothing here to confirm about setup or configuration for that editor. The documented entry points are the command line program, the ANT task and the build plugins.

How do I install Checkstyle?

There is no installer. The README says to download the latest release from GitHub or add Checkstyle to your build from Maven Central, and the repository ships mvnw and mvnw.cmd for building the project itself.

How do I use Checkstyle in IntelliJ IDEA?

The README does not cover IDE integrations at all, so nothing in the repository material confirms how to set Checkstyle up in IntelliJ. The entry points it documents are the command line program, the ANT task and the build plugins.

Official sources

  1. checkstyle/checkstyle on GitHub
  2. License: LGPL-2.1
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/checkstyle-checkstyle.svg)](https://hysenlabs.com/projects/checkstyle-checkstyle)