Checkstyle: enforcing a Java coding standard from the command line and your build
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.
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 or an ANT task, and can be added to a build from Maven Central. 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 November 14, 2026, and from our analysis. They are not legal advice.
Star history
- checkstyle/checkstyle9,648 ★ · +77
| Repository | 2026-09-22 | 2026-11-14 |
|---|---|---|
| checkstyle/checkstyle | 9.6k | 9.6k |
77 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects
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.
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.
$ 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.
$ java -jar checkstyle-10.18.1-all.jar -c config.xml Test.javaExit status is the thing to wire into CI; 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. 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 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.
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 an XML file 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. That is a documentation and process problem, not a defect.
Third, upgrading Checkstyle can change what an existing config.xml does, for example if the DTD version changes. Treat version upgrades as a change that needs its own testing pass.
Checkstyle versus Spotless
Checkstyle and Spotless differ in 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, next to LICENSE. 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-11-02, and recent releases include checkstyle-14.4.0 on 2026-10-31, checkstyle-14.3.0 on 2026-09-27 and checkstyle-14.2.0 on 2026-09-27. 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.
How can I use Checkstyle in Maven?
Add Checkstyle to your build from Maven Central under the artifact com.puppycrawl.tools:checkstyle, The README points to the usage documentation at checkstyle.org/cmdline.html and the configuration documentation at checkstyle.org/config.html.
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. Confirm the task names and config properties in the plugin's own documentation.
How do I use Checkstyle in Visual Studio Code?
The repository description names a command line program and an ANT task as the ways to invoke Checkstyle; check the documentation at checkstyle.org for editor integrations.
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 repository description names a command line program and an ANT task as the ways to invoke Checkstyle; check the documentation at checkstyle.org for IDE integrations.
Official sources
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.
[](https://hysenlabs.com/projects/checkstyle-checkstyle)Star history chart for your README
[](https://hysenlabs.com/projects/checkstyle-checkstyle)Was this useful?