Skip to main content
rule official · GitHub

intellij-java-kotlin — GitHub Copilot rule for Java and Kotlin

A rule that keeps Copilot inside the project's build model when working on Java and Kotlin in IntelliJ IDEA, with validation that matches CI.

Install into GitHub Copilot · Manually: put the files in place All methods and platforms ↓
.github/instructions/intellij-java-kotlin.instructions.md
Open on GitHub

What intellij-java-kotlin does

The rule ships as a repository file and tells Copilot how to behave in Java and Kotlin projects built in IntelliJ IDEA. Build files, repository docs and CI workflows come first; IDE settings do not. Dependencies, source sets, compiler options and test tasks belong in Gradle or Maven rather than only in Project Structure.

It covers project model and build configuration, navigation and refactoring, running and debugging, Kotlin conventions, Spring Boot, and annotation processing with generated sources. IDE actions are treated as optional developer workflows, so the agent should not claim it performed something in the UI without tool evidence. Paid IntelliJ features and extra plugins are off the table.

For Kotlin the rule asks you to keep the configured language and API versions, handle nullability explicitly at Java platform-type boundaries, and skip !! just to silence diagnostics. Coroutines follow the existing scope and dispatcher conventions, with structured concurrency instead of GlobalScope or runBlocking. Spring Boot is only touched in projects that already use it. Formatting checks such as Spotless, Checkstyle, ktlint or detekt are used when the repository already has them.

What it helps with

  • stop build settings from drifting between Gradle and IntelliJ Project Structure
  • edit code without bumping the wrapper, lockfiles or dependency catalog
  • tell the build JDK apart from toolchains and target bytecode
  • validate a change with the CI command instead of a green gutter test
  • keep nullability and coroutine conventions intact in Kotlin

Example prompts for the agent

  • Check that my build.gradle.kts edits don't change the wrapper version or add a new plugin.
  • Figure out why a generated type won't resolve: run the generation task first, then look at the IDE cache.
  • Add a test for this service using the project's existing framework and style, no new dependencies.

How to install intellij-java-kotlin

Manually: put the files in place

.github/instructions/intellij-java-kotlin.instructions.md

The applyTo field sets which files it applies to

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about intellij-java-kotlin

How do I install intellij-java-kotlin in GitHub Copilot?

Add the file at .github/instructions/intellij-java-kotlin.instructions.md in your repository. The rule is picked up through the applyTo globs.

What does intellij-java-kotlin do?

It gives Copilot instructions for Java and Kotlin work in IntelliJ IDEA: Gradle or Maven builds, safe refactorings, run and test setup, Kotlin and Spring Boot conventions.

Does it need paid IntelliJ features or plugins?

No. The rule forbids requiring paid IDE features or extra plugins, and treats IDE actions as optional.

Source text

intellij-java-kotlin.instructions.md · MIT
---
description: 'Guidance for Java and Kotlin development in IntelliJ IDEA with portable Gradle/Maven builds, safe IDE workflows, and CI-aligned validation.'
applyTo: '**/*.java, **/*.kt, **/*.kts, **/*.gradle, **/gradle.properties, **/gradle/*.versions.toml, **/gradle/wrapper/gradle-wrapper.properties, **/gradlew, **/gradlew.bat, **/pom.xml, **/.mvn/**, **/mvnw, **/mvnw.cmd, **/.idea/**, **/*.iml, **/.run/*.run.xml'
---

# IntelliJ IDEA Java and Kotlin Development

Use these instructions for Java and Kotlin projects developed in IntelliJ IDEA. Follow repository-specific conventions first and apply language- or framework-specific guidance only when relevant. IDE actions are optional developer workflows: do not assume Copilot can operate the IDE or claim to have performed actions without tool evidence. Do not require paid IntelliJ features or additional IDE plugins.

## Project Model and Build Configuration

- Treat Gradle or Maven configuration, repository documentation, and CI workflows as the source of truth. Inspect the build files and existing module layout before changing code.
- Import or reload the project from its Gradle settings or Maven root POM. Define dependencies, repositories, source sets, compiler options, and test tasks in the build files rather than only in IntelliJ Project Structure.
- Use the repository's Gradle or Maven wrapper when present. Preserve wrapper versions, dependency catalogs, lockfiles, parent POMs, and dependency-management conventions; do not upgrade tooling as a side effect of an unrelated change.
- Align the IntelliJ project SDK, module SDKs, language level, Gradle JVM, and Maven runner/importer JDK with the build configuration. Distinguish the JDK running the build tool from compilation toolchains and target bytecode; they may intentionally differ. Do not select the newest installed JDK or enable preview features unless the repository requires them.
- After build changes, reload the Gradle or Maven project and resolve synchronization errors before interpreting IDE diagnostics. Fix missing dependencies and source roots in the build model rather than manually adding local JARs or machine-specific paths.

## Editing, Navigation, and Refactoring

- Follow the repository's `.editorconfig`, formatter, import order, and inspection settings. Use configured checks such as Spotless, Checkstyle, ktlint, or detekt only when already present; avoid unrelated whole-file reformatting or new formatter dependencies.
- Use Go to Declaration, Find Usages, and type or call hierarchies to understand a change. Also search configuration, reflection-based lookups, serialization names, and framework conventions that static IDE navigation may miss.
- Prefer semantic Rename, Move, Change Signature, Extract Method, and Safe Delete refactorings over textual replacement when available. Preview the affected usages and review the diff, including Java/Kotlin interop, public APIs, resources, and tests.
- Treat inspections and quick fixes as suggestions, not authority. Check them against the configured language level and project behavior; do not blanket-suppress warnings, weaken inspections, or change compiler settings merely to remove highlighting.
- If IDE actions are unavailable, make equivalent source/build edits with available tools and validate them from the command line. Do not add IDE automation or plugins just to complete a code change.

## Running, Debugging, and Testing

- Match run/debug configurations to the intended module classpath, JDK, working directory, JVM options, application arguments, environment, and active profiles. Keep secrets in the existing environment or secret-management mechanism, not in shared run configurations.
- Use Gradle/Maven tool windows or delegated build/test execution when the project relies on build-tool tasks, generated sources, or custom test setup. An IntelliJ-only compilation or green gutter test is not a substitute for the CI command.
- Use breakpoints, conditional breakpoints, watches, and exception breakpoints to investigate failures. Evaluate expressions cautiously because method calls can mutate state; do not introduce production behavior changes just to simplify debugging.
- Add or update focused tests in the repository's existing framework, source set, naming style, and assertion conventions. Preserve the distinction between unit and integration tests, including required services, profiles, fixtures, and test discovery rules.
- Keep run configurations local unless the repository explicitly shares them. When shared, prefer project-relative paths and documented environment requirements so another developer can reproduce the run.

## Kotlin Conventions

- Preserve the configured Kotlin language/API version, JVM target, and Java interoperability conventions. Do not accept IDE conversions that require a newer compiler or change Java-facing signatures unintentionally.
- Model nullability explicitly, especially at Java platform-type boundaries. Prefer safe calls, Elvis expressions, and explicit validation over introducing `!!` or unchecked casts to silence diagnostics.
- When coroutines are used, follow the existing scope, dispatcher, and lifecycle conventions. Prefer structured concurrency; do not introduce `GlobalScope`, block coroutine threads with `runBlocking`, or swallow cancellation exceptions.
- Use the project's existing coroutine test utilities and controlled dispatchers for asynchronous tests rather than sleeps or timing-dependent assertions.

## Spring Boot Projects

- Follow the existing Spring Boot version, dependency management, package layout, configuration format, profiles, and testing conventions. Do not add Spring Boot to a project that does not use it.
- Prefer the repository's constructor-injection patterns. Preserve component scanning, configuration-property binding, transaction boundaries, and validation behavior when refactoring.
- For Kotlin Spring or JPA code, preserve the build's existing compiler-plugin setup, such as `kotlin-spring` or `kotlin-jpa`, and check annotation use-site targets. Do not make every class `open` or add no-argument constructors simply to satisfy an IDE warning.
- Keep application startup and tests runnable through the existing build tasks or executable artifact. Spring-specific IDE dashboards and inspections are optional, never a prerequisite.

## Annotation Processing and Generated Sources

- Configure annotation processors and code generation in Gradle or Maven, including existing `annotationProcessor`, KSP, or kapt configuration as appropriate. Do not enable a processor only in IntelliJ or migrate between processing mechanisms without a task requirement.
- For unresolved generated types, first run the configured generation/compile task and reload the build model. Check processor dependencies, task ordering, and generated-source directories before treating the issue as an IDE cache problem.
- Treat generated sources as outputs: edit the source annotations, schemas, templates, or generator configuration instead. Do not hand-edit generated classes or copy them into normal source roots.
- Keep generated-source registration and dependencies reproducible in the build. IntelliJ source-root markings or annotation-processing settings must reflect that configuration, not replace it.

## Version Control Hygiene

- Respect `.gitignore` and existing tracking policy. Do not require committing `.idea/`, `*.iml`, or `.run/` files to build or test the project.
- Keep user-specific state such as `.idea/workspace.xml`, local histories, caches, absolute SDK paths, and credentials out of commits. Share only explicitly approved project settings, such as code styles, inspection profiles, or portable run configurations.
- Keep generated outputs such as `build/`, `target/`, `out/`, and `.gradle/` out of version control unless the repository explicitly requires them. Do not confuse the `.gradle/` cache with versioned Gradle wrapper files under `gradle/wrapper/`.
- Preserve intentionally tracked wrapper scripts, wrapper configuration, and required wrapper JARs. Review the diff after IDE synchronization to avoid committing incidental metadata churn.

## Command-Line Validation

- Run the same wrapper, JDK/toolchain configuration, tasks or Maven phases, profiles, and relevant environment settings as CI. Start with focused checks, then run the required broader build, formatting, static-analysis, unit-test, and integration-test checks.
- For a project that provides these tasks, a focused Gradle example is `./gradlew test --tests 'com.example.ExampleTest'`, followed by `./gradlew build`. Use the appropriate module task in a multi-project build and include any additional checks CI runs.
- For a project using the standard Maven test lifecycle, a focused example is `./mvnw -Dtest=ExampleTest test`, followed by `./mvnw verify`. Adapt module selection and profiles to the repository, and verify that integration tests are actually configured and executed.
- In Windows PowerShell, use `.\gradlew.bat` or `.\mvnw.cmd` with the equivalent arguments. If no wrapper exists, use the build-tool version documented by the repository rather than introducing a wrapper without agreement.
- Diagnose IDE/CLI differences by comparing JDKs, classpaths, profiles, generated sources, working directories, and environment settings. Do not fix an IDE-only failure by weakening CI checks.
- Report the commands run and their outcomes. If a check cannot run because a required tool, service, or credential is unavailable, state the limitation explicitly rather than claiming success.

© github · MIT · github/awesome-copilot

Similar IDE rules

All IDE rules for Programming languages →

From the same set732

The whole set →
nestjs This rule feeds GitHub Copilot a set of NestJS conventions: modules, DI, DTOs and validation. Useful when the agent writes TypeScript server code. ★ 40,418repo stars moodle This rule tells Copilot how to write Moodle code: Frankenstyle namespaces, Mustache templates, mandatory security functions. Useful when you build plugins or themes. ★ 40,418repo stars langchain-python A GitHub Copilot instruction file that steers the agent toward LangChain patterns: Runnable, LCEL, chat models, retrievers and vector stores. Useful when your Python code talks to LangChain. ★ 40,418repo stars java-upgrade A rule that points Copilot at the java-upgrade skill whenever you change the Java version in Maven or Gradle files. Handy for LTS jumps. ★ 40,418repo stars github-actions-ci-cd-best-practices A GitHub Copilot rule that guides workflow structure, token permissions, caching and matrix setups whenever you touch files under .github/workflows/. ★ 40,418repo stars genaiscript A GitHub Copilot rule that turns the assistant into a GenAIScript expert: it writes scripts and answers questions about the language. ★ 40,418repo stars draw-io Tells Copilot how to build and edit draw.io diagrams: mxGraph XML structure, a semantic colour palette, grid alignment and a validation script. ★ 40,418repo stars dotnet-maui This rule steers Copilot toward idiomatic .NET MAUI: MVVM, CollectionView over ListView, Shell navigation. Useful once the agent starts editing XAML and C#. ★ 40,418repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor