modern-java-guidance
Guides agents to write Java 17/21+ and Spring Boot 3.x+ code with version detection and the mjg CLI scanner instead of Java 8 and Boot 2.x patterns.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: modern-java-guidancedescription: "Guides agents to write Java 17/21+ and Spring Boot 3.x+ code with version detection and the mjg CLI scanner instead of Java 8 and Boot 2.x patterns."category: developmentrisk: safesource: selfsource_type: selfdate_added: "2026-11-18"author: wkd09tags: [java, spring-boot, java-21, spring-security, cli]Modern Java Guidance
Overview
Prevents AI coding agents from defaulting to Java 8 and Spring Boot 2.x legacy patterns (javax.*, WebSecurityConfigurerAdapter, RestTemplate, @Autowired field injection, Executors.newFixedThreadPool(), list.get(list.size() - 1)). Unlike general persona skills such as java-pro, this skill pairs lightweight instructions with version-gated CLI scanning (mjg detect, mjg check, mjg search, mjg retrieve) and respects older Java 8/11 and Spring Boot 2.x codebases without forcing upgrades.
When to Use
- Writing, refactoring, or reviewing Java 17/21/25+ or Spring Boot 3.x+ application code.
- Auditing an existing Java or Spring Boot codebase for deprecated Boot 2.x or Java 8 idioms.
- Prefer
java-profor broader JVM/GraalVM tuning topics not covered by this skill's rules.
Prerequisites
- Local workspace containing a Java or Spring Boot project (
pom.xml,build.gradle,build.gradle.kts, or.java-version). - Optional: Python 3.11+ with the
mjgCLI (https://github.com/wkd09/modern-java-guidance) for automated version detection and scanning. Everything runs 100% offline with zero external network calls or credentials.
How It Works
1. Establish the inputs
Inspect pom.xml, build.gradle(.kts), gradle/libs.versions.toml, or .java-version (or run mjg detect . if installed).
- Java <= 11 or Spring Boot 2.x: Preserve existing language/framework idioms; do not emit Java 17/21 syntax or
jakarta.*unless explicitly asked to migrate. - Java 17+ / Spring Boot 3.0–3.1: Apply modern replacements (
record,sealed interface,SecurityFilterChainLambda DSL with CSRF enabled by default,jakarta.*, constructor injection,java.time). KeepWebClientorRestTemplate(RestClientrequires Boot 3.2+). - Spring Boot 3.2+: Prefer
RestClient/@HttpExchangeoverRestTemplate. - Java 21+: Prefer Pattern Matching for
switch,SequencedCollection.getLast(), andExecutors.newVirtualThreadPerTaskExecutor()for blocking I/O.
2. Perform the task
Use references/java-21-25-core.md and references/spring-boot-3x.md (or mjg search / mjg retrieve) when writing or updating Java classes. Preserve public/legacy APIs and keep bounded thread pools for CPU-bound tasks.
3. Verify the result
Run mjg check src/ (if installed) and the project's build/test command (./mvnw test or ./gradlew test). Report any remaining warnings or unexecuted build checks explicitly.
Examples
User request: Add a Spring Security configuration for a Spring Boot 3.3 + Java 21 REST API.
Inputs: pom.xml specifying spring-boot-starter-parent 3.3.4 and java.version 21.
Expected result: Generates a @Bean SecurityFilterChain using Lambda DSL (authorizeHttpRequests, requestMatchers) with CSRF protection preserved by default, without WebSecurityConfigurerAdapter or antMatchers(), and passes `mjg check` with 0 findings.
Limitations
- Pattern matching in
mjgrelies on static source scanning rather than full javac AST resolution; always run the project's compiler and test suite (./mvnw test/./gradlew test). - Do not use Java
recordtypes for JPA@Entityclasses, which require mutable state and no-arg constructors.
Safety and side effects
- Read-only code guidance and local static scanning (
risk: safe). mjg detectandmjg checkperform read-only local filesystem reads and never transmit source code over the network.
Sources and related skills
- Source repository: https://github.com/wkd09/modern-java-guidance (MIT License)
- Related skill:
java-pro