A collection of git hooks for Java to be used with the pre-commit framework.
  • Shell 93.6%
  • Dockerfile 6.4%
Find a file
2026-04-02 15:08:40 +00:00
.forgejo/workflows chore: action 2026-04-02 16:00:02 +01:00
sample Added test workflow 2023-04-18 21:26:04 +01:00
.gitignore First import 2020-03-12 21:29:00 +00:00
.markdownlint.json Updated docs 2023-03-03 08:27:29 +00:00
.pre-commit-config.yaml chore: action 2026-04-02 16:00:02 +01:00
.pre-commit-hooks.yaml Updated base image 2023-03-20 12:45:41 +00:00
Dockerfile chore: action 2026-04-02 16:00:02 +01:00
install.sh patch: update tools versions 2026-04-02 15:08:40 +00:00
LICENSE Initial commit 2020-03-12 20:57:21 +00:00
README.md chore: action 2026-04-02 16:00:02 +01:00
ruleset.xml Updated to support major release of PMD 2024-04-01 16:11:18 +01:00
run_checkstyle.sh Added test workflow 2023-04-18 21:26:04 +01:00
run_cpd.sh fix: incorrect arguments parsing 2024-06-06 17:04:17 +05:00
run_pmd.sh pmd: The format parameter can now be overwritten. 2024-09-26 16:23:23 +02:00
tag.sh chore: action 2026-04-02 16:00:02 +01:00
update.sh ci: Fixed update script for PMD 2025-03-06 23:05:41 +05:00

pre-commit-java

pre-commit

A collection of git hooks for Java to be used with the pre-commit framework.

Requirements

pre-commit-java requires the following to run:

Install

  1. create .pre-commit-config.yaml in you git project
  2. pre-commit install
  3. enjoy :)

example .pre-commit-config.yaml:

- repo: https://codeberg.org/gherynos/pre-commit-java
  rev: v0.6.37  # Use the ref you want to point at
  hooks:
    - id: pmd
      exclude: /test/
    - id: cpd
      exclude: /test/
    - id: checkstyle
      exclude: /test/
    # ...

Available Hooks

Hook name Description
pmd Runs the PMD static code analyzer.
cpd Runs the Copy/Paste Detector (CPD).
checkstyle Runs the Checkstyle static code analysis tool.

Notes about the pmd hook

The default ruleset used is ruleset.xml, which runs all the Java rules, except for LoosePackageCoupling.

To specify a custom ruleset, simply pass the argument to the hook:

    - id: pmd
      args: ["-R=my_ruleset.xml"]

Other CLI arguments are also supported, like --cache for incremental analysis.

The arguments must be specified using the --<arg>=<value> (-<arg>=<value>) convention, as opposed to --<arg> <value (-<arg> <value) to avoid parsing errors.

Notes about the cpd hook

The default minimum token length is 100.

To change it, simply pass the argument to the hook:

    - id: cpd
      args: ["--minimum-tokens=50"]

Other CLI arguments are also supported.

The arguments must be specified using the --<arg>=<value> (-<arg>=<value>) convention, as opposed to --<arg> <value (-<arg> <value) to avoid parsing errors.

Notes about the checkstyle hook

The default configuration used is sun_checks.xml.

To specify a custom one, simply pass the argument to the hook:

    - id: checkstyle
      args: ["-c", "my_checks.xml"]

Other CLI arguments are also supported.

Other configurations part of the distribution can be used like:

    - id: checkstyle
      args: ["-c", "/google_checks.xml"]

Author

Codeberg @gherynos

License

pre-commit-java is licensed under the GPLv3 license.