Index of every page on this site: llms.txt
All skills
wkd09 avatar

/modern-java-guidance

@106e8ff
by wkd09wkd09/modern-java-guidance25 stars
4
Run it yourself

Guides coding agents to write modern Java (17/21/25+) and Spring Boot (3.x+) code using version detection and the `mjg` CLI/Hook scanner instead of legacy Java 8 and Spring Boot 2.x patterns. Activate when writing, refactoring, or reviewing Java or Spring Boot projects.

Use this Skill: https://skilld.dev/gh/wkd09/modern-java-guidance/modern-java-guidance

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈73 tokens for metadata: the name and description. ≈1.2k when used: this file. ≈1.2k more on demand in 2 files.

Description uses 3.7% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈293 characters, or 3.7%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Modern Java & Spring Boot Guidance (CLI + Hook + Skill)

LLMs heavily default to Java 8 and Spring Boot 2.x idioms (javax.*, WebSecurityConfigurerAdapter, RestTemplate, @Autowired field injection, new Date(), list.get(list.size() - 1), Executors.newFixedThreadPool). Use this skill and the bundled mjg CLI to detect the project's actual versions and enforce modern equivalents without breaking legacy codebases.


Step 1: Detect Project Versions First

Before writing or refactoring Java code, run mjg detect (or inspect pom.xml / build.gradle.kts / build.gradle / .java-version):

mjg detect .
  • Java <= 11: Respect the project's configured Java version. Do not emit Java 17/21 syntax (record, sealed, SequencedCollection, Virtual Threads) or upgrade the build file unless explicitly requested.
  • Java 17: Use record, sealed classes/interfaces, switch expressions, text blocks, List.of/Map.of, var, and java.time. Do not use Java 21 APIs (SequencedCollection, Virtual Threads, Record Patterns).
  • Java 21+ (or greenfield code): Use Java 21+ idioms including Pattern Matching for switch, Record Patterns, SequencedCollection (getFirst(), getLast(), reversed()), and Virtual Threads (Executors.newVirtualThreadPerTaskExecutor()).
  • Spring Boot 2.x: Keep javax.* and existing Spring Security 5 / RestTemplate APIs unless migrating to Boot 3.
  • Spring Boot 3.0–3.1: Use jakarta.*, SecurityFilterChain + Lambda DSL + requestMatchers(), and constructor injection. (RestClient is not available yet; keep WebClient or RestTemplate.)
  • Spring Boot 3.2–3.3: Also prefer RestClient / @HttpExchange over RestTemplate, and extracted/layered JARs (-Djarmode=tools) for containers.
  • Spring Boot 3.4+: Also replace deprecated @MockBean / @SpyBean with @MockitoBean / @MockitoSpyBean.

Step 2: Legacy vs. Modern Decision Matrix

Category ❌ Legacy (Java 8 / Boot 2.x) ✅ Modern Java 21+ / Spring Boot 3.x+
DTO / Value Objects Verbose POJO or @Data on immutable DTOs public record UserDto(Long id, String email) {}
Type Dispatch if (x instanceof A) { A a = (A) x; ... } Pattern Matching for switch + sealed interface
First / Last Element list.get(0), list.get(list.size() - 1) list.getFirst(), list.getLast(), list.reversed()
I/O Concurrency Executors.newFixedThreadPool(...) for blocking I/O Executors.newVirtualThreadPerTaskExecutor()
Date & Time new Date(), SimpleDateFormat Instant.now(), LocalDate, DateTimeFormatter (java.time)
Collections Collections.unmodifiableList(Arrays.asList(...)) List.of(...), Set.of(...), Map.of(...)
EE Packages (Boot 3+) import javax.persistence.*, javax.validation.* import jakarta.persistence.*, jakarta.validation.*
Spring Security 6 extends WebSecurityConfigurerAdapter, .antMatchers(), .csrf().disable() @Bean SecurityFilterChain, .authorizeHttpRequests(a -> a.requestMatchers(...)), .csrf(AbstractHttpConfigurer::disable)
HTTP Client (Boot 3.2+) new RestTemplate() RestClient.builder() or @HttpExchange
Dependency Injection @Autowired field injection Constructor injection with private final fields

Step 3: On-Demand Guides & References

For token-efficient lookups without loading full reference files, query the built-in catalog:

mjg search "<topic>"      # e.g. mjg search "security" or mjg search "virtual-threads"
mjg retrieve <GUIDE_ID>   # e.g. mjg retrieve BOOT-002

Step 4: Verify With mjg check Before Finishing

After writing or editing .java files, run the version-aware scanner (or let the PostToolUse hook run it automatically):

mjg check src/

Fix all error findings (e.g. javax.*, WebSecurityConfigurerAdapter) and address warning findings unless an external ABI or concurrency constraint (e.g., CPU-bound bounded pool) requires keeping the existing pattern (suppress intentional exceptions inline with // mjg:ignore <RULE-ID>). To enforce the same version-gated rules in CI without mjg, export a Semgrep Java AST ruleset via mjg export --format semgrep --path . -o .semgrep/modern-java.yaml.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts6d3 checks · Risk SAFE
  • Gen Agent Trust Hub6d

    The skill provides guidance for modern Java and Spring Boot development using a specialized CLI tool for version detection and compliance. It adheres to security best practices for framework configuration.

  • Socket6d

    No alerts

  • Snyk6d

    Risk: LOW · No issues

Signed by skilld at 106e8ff. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 5 days ago

README badge

README badge for wkd09/modern-java-guidance