AGENT SKILL
Java 编码测试与日志规范
java-conventions
Java 编码、测试与日志记录规范。
- License 许可
- CC-BY-4.0
- 最近更新
- 2026-10-18
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- java-conventions
- description
- Java coding, testing, and logging conventions.
03 SKILL.md 正文
Java Conventions
Java Version
- Assume projects target at least Java 17. There is no need to worry about backwards compability with older Java releases
- Determine a project's Java language level, based on build tool settings, or existing usages.
- Use Java 25 syntax and API language features, when a project is already using Java 25.
Syntax
- Use pattern-matching
instanceofwhen possible - NEVER use fully qualified class names; ALWAYS add any required missing imports instead;
e.g. generate code using
new HashMap<>();instead ofnew java.util.HashMap<>();etc.
Testing
- If the project uses modern JUnit v5 (Jupiter) API, then do not prefix JUnit @Test methods with
test, just use a descriptive name without the prefix. Do usetestprefixes on projects with older JUnit versions which still required this. - Use Google Truth instead of JUnit's own (or any other) assertions, where possible.
For testing that exceptions are thrown, use
org.junit.jupiter.api.Assertions.assertThrowsbecause Google Truth doesn't have an equivalent. - Always annotate methods (whether
staticor not) with@VisibleForTesting(com.google.common.annotations.VisibleForTesting) whenever they are not markedprivate(e.g. package-private) so that they can be tested. - Refer to the
testingskill for how to execute the tests for the project.
Structure
- Name unused variables
_instead ofunused - Use
varfor local variable declarations where the type is obvious from the right-hand side - Every new package must contain a package-info.java file with a package description and @NullMarked.
Logging
- Use SLF4j API for logging
- Never use
System.err.println()ore.printStackTrace(). Use a SLF4j logger instead, add it if it's missing. - Logger should never be constructor injected, but always simply be a static final field.
Guava
- Use Guava's Immutable Collections instead of Java Collections Framework where appropriate
- Use Guava utilities instead of JDK equivalents where appropriate
- Use Guava's
Strings.isNullOrEmpty()instead ofstring == null || string.isBlank()
Jackson
- Because we always compile with -parameters, we typically do not need to add any @JsonCreator or @JsonProperty
annotations - except on both interfaces and for enum values, where they ARE required. (If a project's build
tool configuration is missing whatever that tool's way to use
-parametersis, then enable it.)
Library Documentation and API Discovery
When you need to look up public APIs, method signatures, Javadocs, or usage examples for external Java libraries (such as Maven Central dependencies):
- Context7 MCP: First use the
resolve-library-idandquery-docsMCP tools to find documentation, code snippets, and usage patterns. - javadoc.io: Use
read_url_contentto fetch class documentation fromhttps://www.javadoc.io/static/<groupId>/<artifactId>/<version>/...(e.g.allclasses-index.html, package summaries, or class Javadocs). - Source Inspection: If you need to understand internal implementation details, look for the
-sources.jaror view the upstream GitHub repository (via GitHub MCP or web). - Bytecode Disassembly Anti-pattern: NEVER run
javapor complexgreppipelines against cached.jarfiles in~/.gradle/cachesto discover Java APIs or method signatures.
Other
- Uses ErrorProne for static analysis; follow it recommendations
- Uses JSpecify annotations for nullability (
@Nullable,@NonNull). Always replace any existingjavax.annotationwith it.
04 同仓库更多 Skills
Michael Vorburger 个人资料
vorburger-profile
提供关于 Michael Vorburger 的个人及职业信息。
★ 0
TypeScript 编码规范
typescript-conventions
强制执行 TypeScript 及项目特定的编码标准,包括 Bun 的使用和零警告策略。在创建或修改任何 TypeScript 或配置文件时使用此技能。
★ 0
项目测试方案制定
testing
根据项目内容确定如何进行测试的指南。
★ 0
Agent Skills 文件规范
skills
Agent Skills 文件的编写规则。
★ 0
脚本编写与执行规范
scripting
编写和执行脚本(TS、Bash 等)的约定规范。
★ 0
常用任务首选工具
preferred-tools
代码检查(linting)、链接检查等常见任务的首选工具。
★ 0