Home › Java › Java + Gradle Copilot path instructions
Java + Gradle Copilot path instructions
Path-specific Copilot instructions for Java 25 LTS code built with Gradle: records, null safety, and JUnit 5 tests.
GitHub CopilotJava
How to use
Save this as .github/instructions/java.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
.github/instructions/java.instructions.mdDownload ---
applyTo: "**/*.java,**/*.gradle.kts"
description: Java conventions
---
# Java (25 LTS) with Gradle
- Build with `./gradlew build`; tests `./gradlew test`; format with Spotless (`./gradlew spotlessApply`) if configured.
- Dependencies go in `gradle/libs.versions.toml`, referenced as `libs.foo`; no inline version strings in `build.gradle.kts`.
- Use `record`s for data carriers, `sealed` interfaces + `switch` pattern matching for closed hierarchies, `var` for obvious local types.
- Avoid `null` in APIs: return `Optional` for absent single values, empty collections for lists. Annotate with JSpecify `@Nullable` where the project uses it.
- Immutable collections (`List.of`, `stream().toList()`).
- Constructor injection with `final` fields; no field injection.
- Exceptions: specific unchecked exceptions for programming errors; never swallow exceptions or catch `Throwable`.
- Concurrency: virtual threads (`Executors.newVirtualThreadPerTaskExecutor()`) for blocking I/O; don't pool virtual threads.
- Logging via SLF4J with placeholders (`log.info("Saved {}", id)`).
- Text blocks for multi-line SQL/JSON in tests.
## Tests
JUnit 5 + AssertJ; `@ParameterizedTest` for input tables; Testcontainers for real databases.