一键导入
java-developer
Guide for developing on the Java 21 baseline, including modern features, best practices, and integration with Groovy/Grails projects
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide for developing on the Java 21 baseline, including modern features, best practices, and integration with Groovy/Grails projects
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Comprehensive guide for current Grails development, covering web applications, REST APIs, GORM, controllers, services, views, plugins, and testing with Spock and Geb
Expert guide for Groovy 5 development, covering concise syntax, closures, DSLs, metaprogramming, static compilation, and integration with Java 21 and Grails
Guide for upgrading Grails applications from Grails 7.x to Grails 8, covering Java 21, Spring Boot 4.1, Spring Framework 7, dependency management, Micronaut, Jackson 3, Hibernate 7, TagLibs, testing, content negotiation, and validation behavior changes
Guide for working in the grails-data-hibernate7 module, especially Hibernate 7 domain binding, mapping migration, generators, and integration tests. Use this when changing code or tests under grails-data-hibernate7.
Guide for running, interpreting, and fixing code style and analysis violations in grails-core using GrailsCodeStylePlugin, GrailsCodeAnalysisPlugin, and GrailsViolationAggregationPlugin — covering CodeNarc, Checkstyle, PMD, SpotBugs, and JaCoCo
Guide for running, reviewing, and fixing test failures across grails-core modules using Gradle test reports
| name | java-developer |
| description | Guide for developing on the Java 21 baseline, including modern features, best practices, and integration with Groovy/Grails projects |
| license | Apache-2.0 |
Use this skill when working on Java code within this repository, especially for:
Immutable data carriers with auto-generated constructors, accessors, equals, hashCode, and toString:
public record Book(String title, String author, int year) {
// Compact constructor for validation
public Book {
if (title == null || title.isBlank()) {
throw new IllegalArgumentException("Title cannot be blank");
}
}
}
Restrict which classes can extend or implement a type:
public sealed interface Shape permits Circle, Rectangle, Triangle {
double area();
}
public final class Circle implements Shape {
private final double radius;
public Circle(double radius) { this.radius = radius; }
public double area() { return Math.PI * radius * radius; }
}
public non-sealed class Rectangle implements Shape {
// Can be further extended
}
Eliminate redundant casts:
// Before pattern matching
if (obj instanceof String) {
String s = (String) obj;
System.out.println(s.length());
}
// Modern Java
if (obj instanceof String s) {
System.out.println(s.length());
}
Multi-line string literals with proper formatting:
String json = """
{
"name": "Grails",
"version": "7.0"
}
""";
String sql = """
SELECT id, name, created_at
FROM users
WHERE status = 'ACTIVE'
ORDER BY created_at DESC
""";
Use switch as an expression with arrow syntax:
String result = switch (day) {
case MONDAY, FRIDAY, SUNDAY -> "Relaxed";
case TUESDAY -> "Productive";
case THURSDAY, SATURDAY -> "Moderate";
case WEDNESDAY -> {
var temp = calculateWorkload();
yield temp > 5 ? "Busy" : "Normal";
}
};
Detailed NPE messages showing exactly which variable was null:
Cannot invoke "String.length()" because "user.getAddress().getCity()" is null
// Stream.toList() - unmodifiable list
List<String> names = users.stream()
.map(User::getName)
.toList();
// Collectors improvements
Map<Status, List<User>> byStatus = users.stream()
.collect(Collectors.groupingBy(User::getStatus));
Groovy seamlessly calls Java code:
// Java record used in Groovy
def book = new Book("Grails Guide", "Author", 2024)
println book.title() // Groovy can use property syntax too
println book.title // Also works
// Groovy classes are just Java classes
GroovyService service = new GroovyService();
service.process(data);
// Working with Groovy closures in Java
Closure<String> closure = ...;
String result = closure.call("input");
@CompileStatic equivalent behavior.java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs += ['-parameters'] // Preserve parameter names
}
@Test
@DisplayName("Book record should validate title")
void bookShouldValidateTitle() {
assertThrows(IllegalArgumentException.class, () ->
new Book("", "Author", 2024)
);
}
@ParameterizedTest
@ValueSource(strings = {"", " ", " "})
void blankTitlesShouldBeRejected(String title) {
assertThrows(IllegalArgumentException.class, () ->
new Book(title, "Author", 2024)
);
}
def "Java record should work in Spock tests"() {
when:
def book = new Book("Test", "Author", 2024)
then:
book.title() == "Test"
book.author() == "Author"
}
# Recommended GC for most workloads
-XX:+UseG1GC
# For low-latency requirements
-XX:+UseZGC
# Memory settings
-Xms512m -Xmx2g
# Enable JFR for profiling
-XX:StartFlightRecording=duration=60s,filename=recording.jfr
public Optional<User> findById(Long id) {
return Optional.ofNullable(repository.get(id));
}
// Usage
String name = findById(id)
.map(User::getName)
.orElse("Unknown");
try (var reader = new BufferedReader(new FileReader(path));
var writer = new BufferedWriter(new FileWriter(output))) {
reader.lines()
.map(String::toUpperCase)
.forEach(line -> writer.write(line + "\n"));
}
// Create immutable collections
List<String> list = List.of("a", "b", "c");
Set<String> set = Set.of("x", "y", "z");
Map<String, Integer> map = Map.of("one", 1, "two", 2);
// Copy to immutable
List<String> copy = List.copyOf(mutableList);
var for local variables when the type is obvious from context.@Override annotation when overriding methods.-parameters flag).