Help us improve
Share bugs, ideas, or general feedback.
From java
Java核心开发规范 - Java 21+现代特性(Records、Pattern Matching、Sealed Classes、Text Blocks)、Maven/Gradle项目结构与工具链配置。编写、重构、初始化Java项目时加载。
npx claudepluginhub lazygophers/ccplugin --plugin javaHow this skill is triggered — by the user, by Claude, or both
Slash command
/java:coresonnetThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- **java:dev** - 开发阶段使用
Provides expertise in Java 21+ features like virtual threads, pattern matching, records, Spring Boot 3.x, GraalVM, Project Loom, and cloud-native enterprise apps.
Enforces Java coding standards for Spring Boot and Quarkus services: naming, immutability, Optional, streams, exceptions, generics, CDI, reactive patterns, and project layout.
Enforces Java 17+ coding standards for Spring Boot services: naming, immutability, Optional, streams, exceptions, generics, and project layout.
Share bugs, ideas, or general feedback.
instanceof pattern 和 switch pattern matchinglog.info("user={}", id))// Record - 不可变数据载体
public record UserResponse(Long id, String email, String name) {
// 紧凑构造函数(compact constructor)
public UserResponse {
Objects.requireNonNull(email, "email must not be null");
}
// 从 Entity 转换的工厂方法
public static UserResponse from(User entity) {
return new UserResponse(entity.getId(), entity.getEmail(), entity.getName());
}
}
// Sealed Classes - 受限类型层次
public sealed interface Shape permits Circle, Rectangle, Triangle {
double area();
}
public record Circle(double radius) implements Shape {
public double area() { return Math.PI * radius * radius; }
}
// Pattern Matching for switch
String describe(Shape shape) {
return switch (shape) {
case Circle c when c.radius() > 10 -> "large circle: r=" + c.radius();
case Circle c -> "circle: r=" + c.radius();
case Rectangle r -> "rectangle: %dx%d".formatted(r.width(), r.height());
case Triangle t -> "triangle: base=" + t.base();
};
}
// Pattern Matching for instanceof
if (obj instanceof String s && s.length() > 5) {
process(s.toUpperCase());
}
// Switch Expressions
int numLetters = switch (day) {
case MONDAY, FRIDAY, SUNDAY -> 6;
case TUESDAY -> 7;
default -> throw new IllegalArgumentException("Unknown day: " + day);
};
// Stream API + toList()(Java 16+, unmodifiable)
List<String> activeEmails = users.stream()
.filter(User::isActive)
.map(User::getEmail)
.toList();
// Text Blocks
String json = """
{
"name": "%s",
"email": "%s"
}
""".formatted(name, email);
// Gradle 8.x + Version Catalog(推荐)
// gradle/libs.versions.toml
[versions]
spring-boot = "3.3.0"
junit = "5.11.0"
testcontainers = "1.20.0"
[libraries]
spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" }
# SpotBugs 静态分析
./gradlew spotbugsMain
# Checkstyle 代码规范
./gradlew checkstyleMain
# JaCoCo 覆盖率
./gradlew test jacocoTestReport
# OWASP 依赖检查
./gradlew dependencyCheckAnalyze
src/main/java/com/example/app/
├── config/ # @Configuration、@ConfigurationProperties
├── controller/ # @RestController(薄层,仅路由和验证)
├── service/ # @Service(业务逻辑,事务边界)
├── repository/ # @Repository(数据访问,Spring Data JPA)
├── domain/ # JPA Entity(持久化模型)
├── dto/ # Record DTO(请求/响应模型)
├── exception/ # Sealed exception 层次结构
└── infra/ # 基础设施(外部 API 客户端、消息队列)
src/test/java/com/example/app/
├── unit/ # 单元测试(@ExtendWith(MockitoExtension.class))
├── integration/ # 集成测试(@SpringBootTest + @Testcontainers)
└── architecture/ # 架构测试(ArchUnit)
| AI 可能的理性化解释 | 实际应该检查的内容 |
|---|---|
| "这是简单 POJO,不需要 Record" | 不可变数据是否使用了 Record? |
| "Lombok 更方便" | 是否避免了 Lombok @Data/@Value? |
| "if-else instanceof 够清晰" | 是否使用了 Pattern Matching? |
| "普通 class 继承就行" | 类型层次是否使用了 Sealed Classes? |
| "Maven 够稳定" | 是否使用了 Gradle Version Catalog 管理版本? |
| "手动格式化代码" | 是否配置了 Checkstyle/SpotBugs 自动检查? |