java-lang
Java development workflow - build tooling, testing, code style, and common patterns such as Optional versus null, exceptions, and how to structure packages in a Spring or plain Java app. Use for writing, reviewing or testing Java code.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- java-lang
- description
- Java development workflow - build tooling, testing, code style, and common patterns such as Optional versus null, exceptions, and how to structure packages in a Spring or plain Java app. Use for writing, reviewing or testing Java code.
02 资源文件 2
- 参考文档evals/eval_queries.json936 B
- 参考文档evals/evals.json4.5 KB
03 SKILL.md 正文
Java Development
You assist with Java development following modern Java conventions and standard build tooling.
Build
Maven
mvn clean compile
Gradle
./gradlew build
- Always use the Gradle wrapper (
./gradlew) — never a system-installed Gradle - Use
--console=plainin CI for clean log output - Build all modules before moving on. Fix compilation errors first.
Test
# Maven
mvn test
# Gradle
./gradlew test
- Use JUnit 5 (
org.junit.jupiter) — not JUnit 4 - Use
@DisplayNamefor readable test names - Use
@Nestedclasses to group related tests - Use
@ParameterizedTestwith@CsvSource,@MethodSource, or@EnumSourcefor table-driven tests - Use AssertJ for fluent assertions:
assertThat(result).isEqualTo(expected)
Test patterns
@Nested
@DisplayName("UserService.create")
class Create {
@Test
@DisplayName("creates user with valid input")
void createsUserWithValidInput() {
var input = new CreateUserRequest("alice", "alice@example.com");
var result = service.create(input);
assertThat(result.name()).isEqualTo("alice");
}
@Test
@DisplayName("rejects duplicate email")
void rejectsDuplicateEmail() {
service.create(new CreateUserRequest("alice", "alice@example.com"));
assertThatThrownBy(() -> service.create(new CreateUserRequest("bob", "alice@example.com")))
.isInstanceOf(DuplicateEmailException.class);
}
}
- Use
@TempDirfor filesystem isolation - Use Mockito sparingly — prefer real implementations and in-memory fakes over mocks
- Integration tests in a separate source set (
src/integrationTest/java)
Format and Lint
Formatting
Use a consistent formatter configured once for the project:
- google-java-format:
mvn com.spotify.fmt:fmt-maven-plugin:format - Spotless (Gradle):
./gradlew spotlessApply - IntelliJ: Use
.editorconfigand shared code style XML
Static analysis
- SpotBugs: Find common bug patterns
- Error Prone: Compile-time error checking (recommended as a compiler plugin)
- Checkstyle: Code style enforcement
Fix issues directly rather than suppressing warnings unless there's a genuine false positive.
Dependency management
Maven
<dependencyManagement>
<dependencies>
<!-- Pin versions here -->
</dependencies>
</dependencyManagement>
Gradle
dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.x.x"))
}
- Use BOMs (Bill of Materials) to manage transitive dependency versions
- Keep dependencies up to date — use Dependabot or Renovate
- Check licenses before adding new dependencies
- Prefer well-maintained, widely-used libraries over niche ones
Project structure
project/
├── src/
│ ├── main/java/com/example/project/
│ │ ├── domain/ # Domain objects, business rules
│ │ ├── service/ # Business logic, orchestration
│ │ ├── repository/ # Data access
│ │ ├── controller/ # API endpoints
│ │ └── config/ # Configuration classes
│ ├── main/resources/
│ │ └── application.yml
│ └── test/java/com/example/project/
│ └── (mirrors main structure)
├── pom.xml / build.gradle.kts
└── .editorconfig
- Package by feature, not by layer, for larger projects:
com.example.project.ordercontains the controller, service, repository, and domain objects for orders - Keep the package hierarchy flat — avoid deep nesting
Code patterns
Records and sealed types (Java 17+)
Use records for immutable data carriers:
public record CreateUserRequest(String name, String email) {}
Use sealed interfaces for closed type hierarchies:
public sealed interface Result<T> {
record Success<T>(T value) implements Result<T> {}
record Failure<T>(String error) implements Result<T> {}
}
Optional
- Return
Optional<T>from methods that may not have a result — never return null - Don't use
Optionalas a method parameter or field — it's for return types - Use
orElseThrow()with a descriptive exception, notget()
Error handling
- Use specific exception types, not generic
RuntimeException - Wrap and rethrow with context:
throw new OrderCreationException("Failed to create order for user " + userId, cause) - Don't catch
Exceptionbroadly — catch specific types - Use try-with-resources for all
AutoCloseableresources - Never swallow exceptions with an empty catch block
Null safety
- Annotate parameters and return types with
@Nullable/@NonNull(JetBrains or Jakarta annotations) - Fail fast on unexpected nulls at public API boundaries:
Objects.requireNonNull(param, "param must not be null") - Prefer empty collections over null: return
List.of()notnull
Modern Java
- Use
varfor local variables where the type is obvious from context - Use text blocks (
""") for multi-line strings - Use
switchexpressions with pattern matching (Java 21+) - Use virtual threads (Java 21+) for I/O-bound concurrent work instead of thread pool tuning
- Use
StreamAPI for collection transformations, but keep pipelines short and readable
CI pipeline
Standard CI jobs:
- Build —
mvn compile/./gradlew compileJava - Test —
mvn test/./gradlew test - Lint — SpotBugs, Error Prone, Checkstyle
- Format Check — Spotless or google-java-format in check mode
- All Clear — aggregator job for branch protection
Use the project's Java version via a .java-version file or toolchains configuration.
04 同仓库更多 Skills
doctor
暂无简介
add-seat
Add a named seat to a Wheelhouse - a crew member, a standing role (such as a dispatcher) or a worker - as a ynh harness with its charter, standing orders and only the tools its job needs, named from the Wheelhouse's roster. Use when asked to add, create or set up a seat, role, worker or agent in a Wheelhouse (a release manager, a PR watcher, a dispatcher, a designer, more workers), or to give a role a name, or to start on a Wheelhouse's team (its starter team), one role at a time. Also use to trial, make official or drop a seat.
voice
How voices work - what a voice skill contains, how to write a new one, and how several voices compose into one reply. Use whenever drafting a reply in a named voice, or when asked to create or change a voice.
voice-warm
A friendly voice that acknowledges the person and their effort. Compose with direct for friendly but brief.
voice-formal
A careful, complete voice for people outside the team - customers, partners, senior stakeholders.
voice-direct
A plain, brief voice that leads with the answer. The default when no voice is named.