plugins/languages/java/skills/core/SKILL.md
Java 核心规范 — Java 21/25 LTS 现代特性 (Records、Pattern Matching、Sealed Classes、Switch Expressions、Text Blocks、Stream Gatherers)、Maven 4/Gradle 9 构建工具链、Version Catalog、SpotBugs/Checkstyle/JaCoCo 质量门禁。当用户编写、重构、初始化 Java 项目,或讨论 "Java 25 特性"、"Records 怎么写"、"Pattern Matching"、"Sealed Classes"、"Switch Expression"、"Stream API"、"Gradle 升级"、"Maven 项目结构" 时加载。
npx skillsauth add lazygophers/ccplugin java-coreInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
声明式规范。AI 编写/审查 Java 代码时必须遵守以下约束并按检查清单自检。
--release 21 或 --release 25,禁止 --source/--target 单独使用@Data/@ValueOptional.get() 不检查;用 map/flatMap/orElseThrowAutoCloseable.toList() (不可变);集合操作不用传统 for@Autowired 字段注入log.info("user={}", id);禁字符串拼接、禁 System.out.println| 特性 | 版本 | 用途 |
|------|------|------|
| Records | 16+ 正式 | 不可变数据载体 |
| Sealed Classes | 17+ 正式 | 受限类型层次 |
| Pattern Matching for instanceof | 16+ 正式 | 类型守卫 |
| Pattern Matching for switch | 21+ 正式 | 模式匹配分支 |
| Virtual Threads | 21+ 正式 | I/O 密集并发 |
| Sequenced Collections | 21+ 正式 | getFirst/getLast |
| Generational ZGC | 21+ 正式 | 低延迟 GC |
| String Templates | 21-23 预览,后撤回 | 禁用 (规范未定型) |
| Structured Concurrency | 25 正式 | 并发任务作用域 |
| Scoped Values | 25 正式 | 替代 ThreadLocal |
| Stream Gatherers | 24+ 正式 | 自定义 Stream 中间操作 |
| FFM API | 22+ 正式 | 替代 JNI |
| Flexible Constructor Bodies | 25+ 正式 | super() 前可校验 |
// Record + 紧凑构造
public record UserResponse(Long id, String email, String name) {
public UserResponse {
Objects.requireNonNull(email, "email");
}
public static UserResponse from(User u) {
return new UserResponse(u.getId(), u.getEmail(), u.getName());
}
}
// Sealed + Pattern Matching for switch
public sealed interface Shape permits Circle, Rectangle, Triangle {}
public record Circle(double r) implements Shape {}
public record Rectangle(double w, double h) implements Shape {}
public record Triangle(double base, double height) implements Shape {}
double area(Shape s) {
return switch (s) {
case Circle c when c.r() > 100 -> throw new IllegalArgumentException("too large");
case Circle c -> Math.PI * c.r() * c.r();
case Rectangle r -> r.w() * r.h();
case Triangle t -> 0.5 * t.base() * t.height();
};
}
// Pattern Matching for instanceof
if (obj instanceof String s && !s.isBlank()) {
process(s.strip());
}
// Stream + toList
List<String> emails = users.stream()
.filter(User::isActive)
.map(User::getEmail)
.toList();
# gradle/libs.versions.toml
[versions]
java = "25"
spring-boot = "3.4.0"
junit = "5.11.4"
mockito = "5.14.0"
testcontainers = "1.20.4"
assertj = "3.26.3"
[libraries]
spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" }
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
./gradlew spotbugsMain # 静态分析
./gradlew checkstyleMain # 风格
./gradlew test jacocoTestReport # 覆盖率 ≥80%
./gradlew dependencyCheckAnalyze # OWASP CVE 扫描
src/main/java/com/example/app/
├── config/ @Configuration、@ConfigurationProperties (record)
├── controller/ @RestController (薄层:路由 + 校验)
├── service/ @Service (业务 + 事务边界)
├── repository/ @Repository (Spring Data)
├── domain/ JPA Entity
├── dto/ Record DTO
├── exception/ sealed 异常层次
└── infra/ 外部 API / MQ 客户端
src/test/java/com/example/app/
├── unit/ 单元测试 (Mockito)
├── integration/ 集成 (TestContainers)
└── architecture/ ArchUnit
| AI 易犯解释 | 实际应核验 |
|---------|---------|
| "Lombok @Data 简洁" | 是否用 Record? |
| "if-else instanceof 清楚" | 是否用 Pattern Matching switch? |
| "继承一下就好" | 类型层次是否 sealed? |
| "Maven 也行" | 是否用 Gradle Version Catalog? |
| "String 拼接日志" | 是否 SLF4J {} 占位? |
| "返回 null 表示没有" | 是否 Optional? |
--release 21 或 25.toList()development
Go 数据库规范——GORM Model 命名 ModelXxx、表名单数、枚举 uint8 + 常量、索引 idx_ 前缀 + deleted_at leading column、禁 time.Time 统一 int64 unix、禁指针/nullable 字段、TEXT/BLOB/JSON 禁 default、AutoMigrate 禁改主键。设计 DB model、写 GORM tag、建索引、做 migration 审查时触发。
development
Go HTTP API 规范——响应始终 200 + body code 字段、路由 /api/* 全 POST 单段 <Action><Model>、中间件逐路由注册禁 Group(prefix,mw...)、handler 仅返回 (rsp,error)、认证走 header。设计 HTTP API、写路由/handler/中间件时触发。
development
Go 项目结构规范——三层架构(API → Impl → State)、全局状态模式、internal/ 私有包、cmd/ 仅 main.go、go.work 多模块、禁止 Repository 接口和 DI 容器、struct 公共字段开头全 omitempty、handler var rsp 顶声明、禁 legacy migration。设计项目骨架、新建目录、组织包、做架构评审时触发。
development
Go 命名规范——Id/Uid 字段(非 ID)、IsActive/HasMFA 布尔前缀、CreatedAt 时间字段、接收者统一用 p、包名全小写无下划线、泛型类型参数描述性命名、集合字段 xxx_list 禁 xxxs 复数、Enum 0 值 XxxNil 禁 Unknown、禁 Status 统一 State、Set/Update 语义区分。定义结构体字段、函数、变量、包、接收者名、泛型、枚举时触发。