How to set up Habit Hooks on a Java repo.
Worked on Solr (Gradle) and Apache Commons Text (Maven). The config files are in
kit/habit-hooks/java/.
uv tool install --force habit-hooks --with habit-hooks-javaA forced install replaces every plugin, so add a--withfor each plugin you already use.brew install pmd jscpd
- Copy
kit/habit-hooks/java/.habit-hooks/andkit/habit-hooks/java/.jscpd.jsonto the repo root. - Copy
kit/tools/run-habit-hooks.shtotools/(it is already set toPLUGIN=java). - Run
habit-hooks init. It should report nothing missing. - Run
tools/run-habit-hooks.sh --all. It exits 1 whenever it finds smells; that is not a failure. - Copy
kit/InternalDocuments/habit-hooks.mdinto the repo and fill in the details below. - Commit.
- From the Java plugin (PMD): methods over 12 statements, cyclomatic complexity of 10 or more, 4 or more parameters, nesting deeper than 3, unused locals and imports, empty catches.
- From the generic plugin: files over 200 lines, and duplication (jscpd).
config.tomlscans**/*.javaminus build output (target/for Maven; addbuild/for Gradle).- If PMD can't parse a file, the whole run fails. Exclude that file in
config.tomlwith a!pattern. Solr needed three test files excluded. .jscpd.jsonscans from the repo root inweakmode, so license headers don't count as duplication. It also ignoresimportlines, so shared import blocks aren't reported..habit-hooks/generic/sensors/replaces the jscpd sensor. The stock one reports the whole repo's duplication on every run; this one keeps only clones touching the files you asked about.
- A stale
JAVA_HOMEor an old Maven. Let the build scripts pick the right versions themselves. - Deliberate duplication, such as deprecated classes kept next to their replacements.
Write it down in
habit-hooks.mdso the sweep leaves it alone. - Apache projects run RAT, which fails on new files without a license header.
Exclude the new files from RAT and mark them
export-ignorein.gitattributes.