https://github.com/gherynos/pre-commit-java
A collection of git hooks for Java to be used with the pre-commit framework.
https://github.com/gherynos/pre-commit-java
checkstyle java pmd pre-commit
Last synced: 7 days ago
JSON representation
A collection of git hooks for Java to be used with the pre-commit framework.
- Host: GitHub
- URL: https://github.com/gherynos/pre-commit-java
- Owner: gherynos
- License: gpl-3.0
- Created: 2020-03-12T20:57:20.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2026-01-11T18:34:29.000Z (13 days ago)
- Last Synced: 2026-01-11T21:59:00.113Z (13 days ago)
- Topics: checkstyle, java, pmd, pre-commit
- Language: Shell
- Homepage:
- Size: 50.8 KB
- Stars: 50
- Watchers: 1
- Forks: 24
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pre-commit-java
[](https://github.com/gherynos/pre-commit-java)
[](https://github.com/gherynos/pre-commit-java/actions/workflows/update.yaml)
A collection of git hooks for Java to be used with the [pre-commit framework](http://pre-commit.com).
## Requirements
pre-commit-java requires the following to run:
* [pre-commit](http://pre-commit.com)
* [Docker](https://www.docker.com)
## Install
1. create `.pre-commit-config.yaml` in you git project
2. pre-commit install
3. enjoy :)
example `.pre-commit-config.yaml`:
```yaml
- repo: https://github.com/gherynos/pre-commit-java
rev: v0.2.1 # 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](https://pmd.github.io) static code analyzer. |
| `cpd` | Runs the [Copy/Paste Detector (CPD)](https://pmd.github.io/pmd-6.22.0/pmd_userdocs_cpd.html). |
| `checkstyle` | Runs the [Checkstyle](https://checkstyle.sourceforge.io) static code analysis tool. |
### Notes about the `pmd` hook
The default ruleset used is [ruleset.xml](https://github.com/gherynos/pre-commit-java/blob/master/ruleset.xml), which runs all the Java rules, except for `LoosePackageCoupling`.
To specify a custom ruleset, simply pass the argument to the hook:
```yaml
- id: pmd
args: ["-R=my_ruleset.xml"]
```
Furthermore, the default language version passed to PMD is `java-17`, which can be tweaked using the `--use-version` argument.
Other [CLI](https://pmd.github.io/latest/pmd_userdocs_cli_reference.html#options) arguments are also supported, like `--cache` for incremental analysis.
The arguments must be specified using the `--=` (`-=`) convention, as opposed to `-- =` (`-=`) convention, as opposed to `-- GitHub [@gherynos](https://github.com/gherynos)
## License
pre-commit-java is licensed under the [GPLv3](https://github.com/gherynos/pre-commit-java/blob/master/LICENSE) license.