stack-java
Skill0 starsChanged 5 months agoApache-2.0View on GitHub
Java/JVM language, build, and testing patterns for agents working in projects whose docs/TECH_STACK.md lists java. Framework-agnostic core — load alongside the framework overlay (e.g. stack-quarkus) when implementing, testing, or reviewing JVM code.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Snakeblack/ospec-workflowtheir own version, first seen Nov 29, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Snakeblack/ospec-workflow★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository17 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- flow-adoptionSkill
- flow-legacy-migrationSkill
- stack-awsSkill
- stack-azureSkill
- stack-design-systemSkill
- stack-gcpSkill
- stack-kafkaSkill
- stack-mongodbSkill
- stack-natsSkill
- stack-nestjsSkill
- stack-nextjs-reactSkill
- stack-nxSkill
- stack-playwrightSkill
- stack-postgresqlSkill
- stack-quarkusSkill
- stack-react-nativeSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 42
Prefer constructing a new instance over mutating.
- Very specific: line 46
Don't Optional.get() without isPresent.
- Very specific: line 50
Never swallow: always chain the cause (throw new DomainX("...", cause)).
- Distinctive: line 51
Don't use exceptions for control flow over expected outcomes — model those with a sealed result type (above).
- Distinctive: line 74
Mockito sparingly: prefer real collaborators and in-memory implementations of the port interfaces (the abstract-port discipline makes this …
- Very specific: line 104
All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Stack: Java (JVM core)
The framework (Quarkus, Spring, plain) is a SEPARATE overlay — this skill is the language/build/test core every JVM project shares. Read the host's docs/ARCHITECTURE.md and docs/TECH_STACK.md for the JDK baseline and framework before assuming APIs (virtual threads, sealed types, and pattern matching gate on the JDK version).
When this applies
Detection markers (any of):
docs/TECH_STACK.md## Detected stackslistsjava- Build files:
pom.xml,build.gradle/build.gradle.kts,settings.gradle*,mvnw/gradlewwrappers - Sources:
src/main/java/**/*.java,module-info.java - Toolchain pins:
.sdkmanrc,.java-version, a<maven.compiler.release>/toolchainblock
Implementation patterns
These are the patterns this stack commonly uses for an enterprise hexagonal JVM core. Where the host's docs/ARCHITECTURE.md declares different conventions, the host docs win.
Domain modeling — records + sealed hierarchies
// Value object: record gives equals/hashCode/immutability for free.
public record Money(BigDecimal amount, Currency currency) {
public Money { // compact canonical constructor = the invariant gate
if (amount.scale() > currency.getDefaultFractionDigits())
throw new IllegalArgumentException("scale exceeds currency minor units");
amount = amount.stripTrailingZeros(); // normalize before the field is assigned
}
}
// Closed domain outcome: sealed permits exhaustive switch with NO default branch.
public sealed interface TransferResult permits Settled, Rejected, Pending {}- Records for VOs and immutable DTOs; validate/normalize in the compact constructor — never expose a record that can hold an illegal state.
- Sealed interfaces/classes for closed sets (domain outcomes, command unions). Switch over them exhaustively with pattern matching and no
default— adding a permitted type then becomes a compile error at every call site, which is the point. - Entities (identity-based) are NOT records — identity equality is on the ID alone, not all fields. Keep
equals/hashCodeon the immutable ID only.
Immutability by default
- Fields
final; collections returned asList.copyOf(...)/ unmodifiable; defensive-copy mutable inputs (arrays,Date, mutable collections) at the boundary. - Prefer constructing a new instance over mutating. A "setter" on a domain object is a smell unless the host docs declare a mutable-entity ORM pattern.
Absence — Optional at boundaries only
Optional<T>as a RETURN type for "may be absent" lookups. Never an Optional field, parameter, or collection element (Optionalin a collection is an anti-pattern — use an empty collection).- Don't
Optional.get()withoutisPresent; useorElseThrow,map,orElseGet.orElse(expensive())eagerly evaluates — useorElseGetfor non-trivial fallbacks.
Error taxonomy
- Domain errors are unchecked typed exceptions (
extends RuntimeException) carrying structured context, mapped to transport codes at the presentation boundary by the framework overlay — domain code never knows HTTP. - Never swallow: always chain the cause (
throw new DomainX("...", cause)); nevercatch (Exception e) {}. Catch the narrowest type. - Don't use exceptions for control flow over expected outcomes — model those with a sealed result type (above).
Concurrency
- Immutability first — a shared immutable object needs no lock. Reach for
java.util.concurrent(ConcurrentHashMap,Atomic*,BlockingQueue) beforesynchronized; reach forsynchronized/ReentrantLockbefore hand-rolled wait/notify. - Virtual threads (JDK 21+): cheap for blocking I/O fan-out, but
synchronizedblocks PIN a virtual thread to its carrier — useReentrantLockon hot paths that run under virtual threads. Do NOT pool virtual threads. ThreadLocalleaks: anything set on a pooled (platform) thread MUST be cleared infinally, or it bleeds into the next task. Audit MDC/security-context propagation across async boundaries explicitly.- Publish-safety: a non-final field written by one thread and read by another without a happens-before edge is a data race even if it "works" in tests.
Resource & null discipline
try-with-resourcesfor everyAutoCloseable(streams, connections,Scope). Never a bareclose()infinally.- Null-safety via annotations the project already uses (JSpecify /
package-info.java@NullMarked); treat parameters non-null by default and validate at the public boundary (Objects.requireNonNullwith a message). - Streams: no side effects inside lambdas (no mutation of external state, no I/O); they express a transformation, not a loop. For hot/large paths, a plain loop is legitimately faster — don't dogmatically stream.
Persistence — the framework's data module owns the driver (R-PAT-03)
Persistence is a framework concern, not a language one — the repository adapter is built on the framework overlay's first-party data integration, never a hand-managed JDBC Connection/DataSource or raw Mongo client:
- Spring → Spring Data repositories (
spring-boot-starter-data-jpa/spring-data-mongodb): the adapter extends/uses a Spring Data repository interface; Spring owns theEntityManager, the connection pool, and@Transactionalbinding. Do NOT inject a rawDataSource/JdbcTemplate-by-hand or a bareMongoClientwhere a Spring Data module covers the store. - Quarkus → Panache extensions — see
.claude/skills/stack-quarkus/SKILL.md. - Plain JVM / no framework → the bare JDBC/driver client IS the integration; keep it isolated in the adapter behind the port.
- Fallback to a raw driver under a framework is legitimate only for a store the framework has no module for, or hand-tuned SQL the data module cannot express — and it stays inside the adapter, never in domain/application.
Testing on this stack
- Framework: JUnit 5 (Jupiter) + AssertJ for fluent, descriptive assertions. Parameterized tests (
@ParameterizedTest+@MethodSource/@CsvSource) to table-test every boundary value of pure logic — records and sealed-result logic are pure, test them exhaustively. - Mockito sparingly: prefer real collaborators and in-memory implementations of the port interfaces (the abstract-port discipline makes this trivial). Mock only true process boundaries you don't own. Never mock value objects or the type under test.
- Integration: Testcontainers for the real datastore/broker — no in-memory substitutes for the DB (R-TESTI-01: integration tests run real wiring). Reuse a single container per class; don't spin one per method.
- Determinism: inject the clock (
Clockparameter), neverInstant.now()in domain code; seed any randomness. Flaky time/concurrency tests are defects, not retries. - Assert on behavior and structured error types, not on log strings.
Spec validation checks
Stack-specific checks the spec validators (spec-validate-lead-engineer, on SPEC_<FEATURE>.md §4 API & Domain, §5 Business Rules) delegate here:
| Check | Severity |
Closed domain sets modeled as sealed types; switches exhaustive with no default (adding a case is a compile error) | BLOCKER |
| Value objects immutable (records / final fields) and validated at construction — no illegal state representable | BLOCKER |
| Domain errors are typed unchecked exceptions mapped to transport at the boundary; domain has no transport knowledge | BLOCKER |
| Concurrency/visibility behavior specified for shared state (who wins, what is published-safe) | BLOCKER |
Optional used only as a return type, never field/param/collection element | WARNING |
| Absence/error outcomes modeled as result types rather than control-flow exceptions where expected | WARNING |
Clock/randomness injected (no ambient now()/random() in domain) so behavior is testable | WARNING |
Live validation commands
R-VAL-01 matrix (JVM source/test changes) — exact invocations live in docs/DEV_SETUP.md; obligations:
| Check | Typical shape (Maven / Gradle) |
| Compile main + test, fail on warnings | mvn -q compile test-compile / gradle compileJava compileTestJava (compiler -Werror where the project sets it) |
| Run unit + integration tests for affected modules | mvn verify / gradle test integrationTest — the load-bearing row (Testcontainers up) |
| Static analysis / lint if configured | the project's checkstyle/spotbugs/errorprone/spotless target per DEV_SETUP |
| Build the artifact | mvn -q package -DskipTests=false / gradle build |
All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md. Do not weaken a type, widen a catch, or @Disabled a test to go green — fix the cause.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

