A collection of git hooks for the JVM to be used with the pre-commit framework.
pre-commit-jvm requires the following to run:
- create
.pre-commit-config.yaml
in your git project - pre-commit install
example .pre-commit-config.yaml
:
- repo: https://github.com/dustinsand/pre-commit-jvm
rev: vX.X.X
hooks:
- id: detekt
args: [--config, detekt-config.yml]
- id: google-java-formatter-jdk11
args: [--replace, --set-exit-if-changed]
- id: ktlint
args: [--format]
- id: pmd
args: [ -rulesets, pmd-ruleset.xml, -language, java, -cache, .pmd/cache, -dir, src/main/java, -f, textcolor ]
Hook name | Description |
---|---|
detekt |
Runs Detekt static code analyzer on Kotlin source files. |
google-java-formatter-jdk8 |
Runs Google Java Formatter to reformat Java source code to comply with Google Java Style. Minimum supported runtime version is JDK 8. |
google-java-formatter-jdk11 |
Runs Google Java Formatter to reformat Java source code to comply with Google Java Style. Minimum supported runtime version is JDK 11. |
ktlint |
Runs Ktlint to lint and reformat Kotlin source code. |
pmd |
Runs PMD static code analyzer on Java source files. |
To specify a custom detekt configuration, simply pass the argument to the hook:
- id: detekt
args: [--config, detekt-config.yml]
Other CLI arguments are also supported.
Minimum required arguments for the hook:
- id: google-java-formatter-jdk[version]
args: [--replace, --set-exit-if-changed]
Other CLI arguments are also supported.
You can also use Coursier to get the list of options.
[JDK 8]
cs launch com.google.googlejavaformat:google-java-format:1.7 -- --help
[JDK 11+]
cs launch com.google.googlejavaformat:google-java-format:1.9 -- --help
Minimum required arguments for the hook:
- id: ktlint
args: [--format]
Other CLI arguments are also supported.
You can also use Coursier to get the list of options.
cs launch com.pinterest:ktlint:0.39.0 -M com.pinterest.ktlint.Main -- --help
Required arguments for the hook:
Argument | Description |
---|---|
dir | Root directory for sources. |
rulesets | Comma separated list of ruleset names to use. |
- id: pmd
args: [ -dir, src/main/java, -rulesets, pmd-ruleset.xml ]
Other CLI arguments are also supported.