← ~/pillars / deterministic-policy / linters-as-ground-truth

Linters as ground truth

The 2026 Java enforcement stack (Spotless, Checkstyle, Error Prone, PMD, SpotBugs, ArchUnit), the auto-fix versus report split, and how an agent interacts with each.

updated 2026-06-10 ~4 min read pattern 05/06 Deterministic Guardrails

on this page

Context. You have moved the mechanical rules out of CLAUDE.md, as the architecture pattern prescribes. Now something deterministic has to own them. For Java, the tools exist for every rule class: the work is choosing which tool owns which rule and wiring each into a channel the agent actually perceives.

Forces. Tools overlap: Checkstyle, PMD, and Error Prone can all flag a magic number, and overlapping ownership produces contradictory reports the agent ping-pongs between. Tools also differ in a property that matters far more for agents than for humans: whether they fix or merely report. An auto-fix tool can run silently in a hook; a report tool needs its findings delivered into the agent’s context, or the violations simply accumulate until CI fails.

Resolution. One tool per rule class, the auto-fix/report split decides the integration, and the diagnostic question from the pillar landing (could a tool verify this without reading my mind?) decides what enters the stack at all.

The stack, as of June 2026

ToolVersionOwnsAuto-fix?
SpotlessMaven plugin 3.6.0 / Gradle plugin 8.6.0 (May 2026)Formatting: google-java-format, import order, licence headersYes (spotlessApply)
Checkstyle13.5.0 (May 2026)Style beyond formatting: naming, Javadoc, magic numbersNo
Error Prone2.49.0 (current per the releases page, checked 2026-06-10)Compile-time bug patterns: NPE risks, API misuse, threadingLimited (-XepPatchLocation)
PMD7.16.0 (July 2025)Source-level: dead code, empty catch, complexity, copy-pasteNo
SpotBugs4.9.8 (October 2025)Bytecode patterns: null dereference, synchronisation, securityNo
ArchUnit1.4.2 (April 2026)Architecture: layering, cyclic deps, naming conventionsNo

Spotless and ArchUnit versions are verified against their release pages; Checkstyle 13.5.0, PMD 7.16.0, and SpotBugs 4.9.8 are from release-notes search results as of the dates shown. Confirm against the respective project releases before pinning. Error Prone requires JDK 21+ and has had issues on some JDK 21/25 configurations in the 2.47+ line. Pin 2.49.0 and verify against your exact JDK before adopting (errorprone.info).

How the agent meets each tool

The split determines the channel:

Auto-fix tools run in hooks, invisibly. A PostToolUse hook fires spotlessApply on every Java file the agent edits (hooks guide); the file is reformatted before the agent’s next step and formatting never becomes a conversation. The complete hook is the format-on-edit artifact.

Report tools need a feedback loop. Checkstyle cannot fix, so the Checkstyle gate hook runs it after each Java edit and feeds violations back to the agent as a blocking error: the agent fixes them in-session rather than discovering them in CI. PMD and SpotBugs are slower and noisier; run them as CI gates, where a failing check on the PR is the agent’s (or the human’s) signal.

Compiler-borne tools are free. Error Prone runs inside javac, so its findings arrive as compile errors, a channel agents already treat as non-negotiable, with no extra wiring.

Test-borne tools are nearly free. ArchUnit rules are JUnit tests; the agent runs the suite, sees domainHasNoFrameworkImports FAILED, and removes the offending import. This is the highest-leverage tool in the stack for agent work, because architecture boundaries are exactly the rules agents cross while locally “improving” code.

Worked example: wiring the gate tools

Spotless (Maven), formatting plus licence headers. The licence header check runs in CI via the check goal rather than per-edit:

pom.xml (Spotless)
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<java>
<googleJavaFormat/>
<importOrder/>
<removeUnusedImports/>
<licenseHeader>
<file>${project.basedir}/licence-header.txt</file>
</licenseHeader>
</java>
</configuration>
<executions>
<execution>
<goals><goal>check</goal></goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>

Checkstyle carries a trap: the Maven Checkstyle Plugin 3.6.0 bundles Checkstyle 9.3 by default. Without an explicit dependency override you are gating on a four-major-versions-old ruleset:

pom.xml (Checkstyle, with the version override)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.6.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>13.5.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>

Keep formatting modules (whitespace, indentation) out of checkstyle.xml. Spotless owns layout, and overlap here is how agents end up in fix loops.

ArchUnit encodes the hexagonal boundary as a test (archunit.org, 1.4.2, JUnit 5):

src/test/java/com/example/ArchitectureTest.java
@AnalyzeClasses(packages = "com.example")
class ArchitectureTest {
@ArchTest
ArchRule domainHasNoFrameworkImports =
noClasses().that().resideInAPackage("..domain..")
.should().dependOnClassesThat()
.resideInAnyPackage("org.springframework..", "jakarta..");
}

With this in place, the CLAUDE.md architecture section shrinks to one line (“hexagonal; the ArchUnit test enforces the layering, do not suppress violations”), and the rule holds at 100%, not 70–90%. That is the pattern in miniature: every rule that moves from prose to a tool gets cheaper and more reliable at the same time. The enforcement layers themselves (which hook events block, how CI gates agent PRs) are developed in the deterministic policy pillar.

// sources