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.

Related rules

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.