modern-java-21

Enforces modern Java 21+ coding standards on every created or modified .java file.

39|3|Updated Jul 28, 2025
One-click install
npx skills add https://github.com/mzivkovicdev/spring-crud-generator --skill modern-java-21-mzivkovicdev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: modern-java-21
Source: https://github.com/mzivkovicdev/spring-crud-generator/tree/main/.agents/skills/modern-java-21
Command: npx skills add https://github.com/mzivkovicdev/spring-crud-generator --skill modern-java-21-mzivkovicdev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Java codebases drift into inconsistent imports, legacy patterns, null-safety gaps, and oversized classes as they grow. This Skill applies one authoritative coding standard to every touched Java file so production and test code stay readable, safe, and consistent. ## Core Features & Use Cases - Import and style enforcement: Applies a fixed seven-group import order, bans wildcards, var, and field injection, and requires this. qualification and final declarations. - Null safety with JSpecify: Standardizes @NullMarked packages and @Nullable usage, with rules for arrays, generics, entities, and migration of existing packages. - Modern language guidance: Covers records, sealed hierarchies, exhaustive switch expressions, exception translation, constructor injection, method/class size limits, and Javadoc contract rules. - Use Case: When refactoring a Spring Boot service or writing a new one, the Skill ensures the result follows the project's Java 21+ standard, passes quality gates, and keeps tests aligned with the same rules. ## Quick Start Apply the modern-java-21 skill to review and clean up the Java files changed in this task.

Frequently Asked Questions about modern-java-21

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce a consistent Java coding standard across a project?▼

Apply a single authoritative rule set to every touched .java file covering imports, nullability, immutability, and size limits, and back it with build quality gates like Checkstyle MethodLength and FileLength so violations fail the build rather than relying on review alone.

What is the correct import order for Java projects?▼

This standard uses seven groups in order: static imports, java.*, jakarta.*, javax.*, com.*, org.*, then everything else such as io.* or reactor.*. Each group is sorted lexicographically with exactly one blank line between non-empty groups, and wildcard imports are banned.

Should I use var in Java 21 production code?▼

This project standard prohibits var in all project-controlled source, including tests and generated templates, requiring explicit declared types for readability. Java still resolves types statically, but the convention keeps the type visible to readers.

How does JSpecify nullability work with Spring Boot?▼

Every main-source package carries @NullMarked in package-info.java so unannotated types are non-null, and @Nullable marks exceptions. The same org.jspecify.annotations vocabulary works on both Spring Boot 3 and 4, replacing Spring's own @Nullable and JSR-305.

When should I use Optional versus @Nullable in Java?▼

Use Optional only as a return type for a legitimately absent value. For fields, record components, entity attributes, and parameters, use JSpecify @Nullable instead, since it costs no allocation, survives serialization, and maps correctly in JPA.

What are the method and class size limits enforced here?▼

Methods up to 40 lines need no justification, 41-60 require scrutiny, and 61-100 need a documented reason. A method over 100 lines or a class over 1000 lines must be refactored without exception because the build gates fail at exactly those numbers.