Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 29, 2026·3 min de lecture

Checkstyle — Java Code Quality Enforcement Tool

A development tool that checks Java source code against configurable coding standards, supporting Google Java Style and Sun Code Conventions out of the box.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Checkstyle Overview
Commande d'installation directe
npx -y tokrepo@latest install 3bcee49a-5b15-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Checkstyle verifies that Java source code adheres to a coding standard. It ships with the Google Java Style Guide and Sun Code Conventions as built-in configurations, and supports fully custom rulesets. Teams use it in build pipelines to enforce consistent code formatting and naming.

What Checkstyle Does

  • Scans Java source files for coding standard violations
  • Ships with Google Java Style and Sun Code Conventions configurations
  • Supports custom check modules written in Java
  • Integrates with Maven, Gradle, Ant, and IDE plugins
  • Produces reports in XML, plain text, and SARIF formats for CI integration

Architecture Overview

Checkstyle parses Java source files into an abstract syntax tree using its own parser based on ANTLR grammars. Each check module is a TreeWalker listener that inspects specific AST node types. The configuration is an XML file that defines which checks are active and their parameters. Filters and suppressions allow fine-grained control over reported violations.

Self-Hosting & Configuration

  • Add the Maven Checkstyle Plugin or Gradle Checkstyle Plugin to your build file
  • Use the built-in google_checks.xml or sun_checks.xml as a starting point
  • Create a custom checkstyle.xml to enable, disable, or configure individual checks
  • Set up a checkstyle-suppressions.xml file to suppress specific violations by file or pattern
  • Run as a CLI tool by downloading the all-in-one JAR from GitHub releases

Key Features

  • Two industry-standard configurations included out of the box
  • Over 150 checks covering naming, imports, whitespace, Javadoc, and code complexity
  • Suppression filters by file path, check name, or inline @SuppressWarnings annotations
  • SARIF output for GitHub code scanning integration
  • IDE plugins for IntelliJ IDEA, Eclipse, and VS Code

Comparison with Similar Tools

  • PMD — detects code smells, unused variables, and complexity; Checkstyle focuses on formatting and naming conventions
  • SpotBugs — finds runtime bugs through bytecode analysis; Checkstyle works on source code style
  • Error Prone — catches common Java mistakes at compile time; Checkstyle enforces style rules
  • google-java-format — auto-formats code to Google style; Checkstyle reports violations without auto-fixing

FAQ

Q: Can Checkstyle auto-fix violations? A: No. Checkstyle is a reporting tool. Use google-java-format or an IDE formatter for auto-fixing, and Checkstyle for enforcement in CI.

Q: How do I suppress a specific check for one file? A: Add the file pattern to checkstyle-suppressions.xml, or use @SuppressWarnings("checkstyle:CheckName") in the source code.

Q: Does Checkstyle support Java 21+ features? A: Yes. Checkstyle updates its parser to support new Java syntax with each release.

Q: How do I integrate Checkstyle with GitHub Actions? A: Use the Maven or Gradle plugin with SARIF output, then upload results with the github/codeql-action/upload-sarif action.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires