[GH-2189] Add Checkstyle pre-commit hook for Java #2505
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Yes, I have read the Contributor Rules and Contributor Development Guide.
Is this PR related to a ticket?
Yes, and the PR name follows the format [GH-2189] Add Checkstyle pre-commit hook for Java.
Closes #2189.
What changes were proposed in this PR?
This PR adds a Checkstyle pre-commit hook to automatically check Java code formatting and style consistency before each commit.
The hook runs mvn checkstyle:check to detect style violations. Since Spotless already formats Scala code, no new hooks were added for Scala files.
Key changes:
Added Checkstyle configuration to .pre-commit-config.yaml
Integrated it into the existing pre-commit workflow for Java sources
Ensured compatibility with current Maven/Spotless setup
Why are these changes needed?
To improve and enforce Java code style consistency during development. Automating the style check helps contributors detect and fix formatting issues early, ensuring clean and maintainable code before review and CI builds.
How was this patch tested?
Installed pre-commit hooks locally and verified execution
Ran pre-commit run --all-files to confirm the Checkstyle hook triggers correctly
Intentionally introduced style violations to verify detection
Confirmed normal commits proceed when no issues are found
Does this PR include necessary documentation updates?
No, this PR affects only development tooling and does not modify user-facing APIs or documentation.
Does this PR introduce any user-facing changes?
No user-facing changes. This only affects local development workflow.