From java
Java核心开发规范 - Java 21+现代特性(Records、Pattern Matching、Sealed Classes、Text Blocks)、Maven/Gradle项目结构与工具链配置。编写、重构、初始化Java项目时加载。
npx claudepluginhub lazygophers/ccplugin --plugin javaThis skill uses the workspace's default tool permissions.
- **java:dev** - 开发阶段使用
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Guides MCP server integration in Claude Code plugins via .mcp.json or plugin.json configs for stdio, SSE, HTTP types, enabling external services as tools.
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 自动检查? |