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.

More: all Java rules · all GitHub Copilot rules

Related rules

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

ASP.NET Core Copilot instructions

Copilot instructions for ASP.NET Core on .NET 9/10: minimal APIs, EF Core, nullable types, and xUnit tests.

GitHub Copilot.NET / ASP.NET Core

Go Copilot path instructions

Path-specific Copilot instructions (.instructions.md) for Go 1.27 code: errors, context, stdlib routing, and tests.

GitHub CopilotGo

Laravel Copilot instructions

GitHub Copilot instructions for Laravel 11+ apps with Eloquent, Pest, and Form Requests.

GitHub CopilotLaravel

Python Copilot path instructions

Path-specific Copilot instructions for Python 3.12+ files: typing, error handling, uv/ruff tooling, and pytest.

GitHub CopilotPython

Ruby on Rails Copilot instructions

GitHub Copilot custom instructions for Rails 8 apps with Hotwire, RSpec and Rubocop.

GitHub CopilotRuby on Rails

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.