AGENTS.md
compiler/build-tools/AGENTS.mdAGENTS.md
Quality
89/100
Scores the file, not the repository.Length
707 words
19 headings · 4 code blocksRepository
53k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Kotlin Build Tools API (BTA)23An experimental interface for build systems (Gradle plugin, Maven plugin, etc.) to invoke Kotlin compilation without a direct compiler4dependency. Build systems should use the API from `kotlin-build-tools-api`, load the implementation in an isolated ClassLoader, and avoid5accessing compiler internals directly.67## Modules89| Module | Purpose |10|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|11| [`kotlin-build-tools-api`](kotlin-build-tools-api) | Public interfaces only; no implementation; `explicitApi()`; API dump checked in |12| [`kotlin-build-tools-impl`](kotlin-build-tools-impl) | Default implementation; version-coupled to the compiler; must run in isolated ClassLoader |13| [`kotlin-build-tools-compat`](kotlin-build-tools-compat) | Adapter for compilers < 2.3.0 (wraps deprecated `CompilationService`) |14| [`kotlin-build-tools-cri-impl`](kotlin-build-tools-cri-impl) | Protobuf serialization for Compiler Reference Index; shipped as shadow JAR |15| [`kotlin-build-tools-jdk-utils`](kotlin-build-tools-jdk-utils) | Internal utility for Java 9+ platform ClassLoader detection; do not use outside BTA modules |16| [`kotlin-build-tools-generator`](kotlin-build-tools-generator) | KotlinPoet-based code generator producing compiler argument classes from `:compiler:arguments` and API version file |17| [`kotlin-build-statistics`](kotlin-build-statistics) | Shared library for build metric collection (times, performance, GC, attributes); used by impl and KGP |18| [`util-kotlinpoet`](util-kotlinpoet) | KotlinPoet utility helpers shared by code generators in the BTA area |19| [`kotlin-build-tools-api-tests`](kotlin-build-tools-api-tests) | Main integration test suite (JUnit 5, multiple named test suites) |20| [`kotlin-build-tools-api-forward-tests`](kotlin-build-tools-api-forward-tests) | Tests the forward compatibility guarantee (X+1) |2122## Architecture: ClassLoader Isolation2324The impl JAR must be loaded in an isolated ClassLoader to prevent classpath conflicts with the consumer:2526```kotlin27val toolchains = KotlinToolchains.loadImplementation(implClasspath) // implClasspath: List<Path>28```2930- `loadImplementation(List<Path>)` — preferred API; wraps the classpath in a `URLClassLoader` backed by `SharedApiClassesClassLoader`31 automatically32- `loadImplementation(ClassLoader)` — lower-level overload for custom ClassLoader setups; the ClassLoader's parent should be33 `SharedApiClassesClassLoader`34- The impl JAR version must match the compiler version (`kotlin-build-tools-impl` is version-coupled to the compiler)35- For compilers < 2.3.0, include `kotlin-build-tools-compat` in the impl classpath → see [36 `kotlin-build-tools-compat/README.md`](kotlin-build-tools-compat/README.md)3738## Key Abstractions3940All in `kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/`:4142- `KotlinToolchains` — factory entry point; creates `BuildSession` instances (`KotlinToolchains.kt`)43- `BuildSession` (`AutoCloseable`) — manages caches, thread pools, and daemon connections44- `Toolchain` (sealed interface) — `JvmPlatformToolchain`, `CriToolchain`, `AbiValidationToolchain`45- `BuildOperation<R>` / `BuildOperation.Builder` — type-safe operation configuration (`BuildOperation.kt`)46- `ExecutionPolicy` — `InProcess` vs `WithDaemon` (`ExecutionPolicy.kt`)47- `KotlinLogger` — pluggable logging interface (`KotlinLogger.kt`)4849## Generated Files5051Do not edit generated files manually — regenerate them with the tasks below.5253Two kinds — both must be regenerated after relevant changes:5455```bash56# Regenerate generated sources (compiler argument classes and API version file; after changing compiler arguments in :compiler:arguments)57./gradlew :compiler:build-tools:kotlin-build-tools-api:generateBtaSources58./gradlew :compiler:build-tools:kotlin-build-tools-impl:generateBtaSources59./gradlew :compiler:build-tools:kotlin-build-tools-compat:generateBtaSources6061# Regenerate API binary compatibility dump (after any public API change)62./gradlew :compiler:build-tools:kotlin-build-tools-api:apiDump63```6465## Compatibility Model6667```68BTA version X is guaranteed to work with implementation versions [X-3, X+1]69```7071- **Backward compat (X-3):** tested in `kotlin-build-tools-api-tests` compatibility suites (one suite per listed version)72- **Forward compat (X+1):** tested in `kotlin-build-tools-api-forward-tests`73- When adding an API change that may break compatibility, add tests to both modules and run locally to verify7475## Running Tests7677```bash78# Run all tests (testExample is excluded from check — run it explicitly if needed)79./gradlew :compiler:build-tools:kotlin-build-tools-api-tests:check8081# Run against a specific BTA impl version (pattern: testCompatibility<version>)82./gradlew :compiler:build-tools:kotlin-build-tools-api-tests:testCompatibility2.3.208384# Run against current snapshot impl85./gradlew :compiler:build-tools:kotlin-build-tools-api-tests:testCompatibilitySnapshot8687# Classpath/module-path escaping edge cases88./gradlew :compiler:build-tools:kotlin-build-tools-api-tests:testEscapableCharacters8990# Verify restricted arguments are rejected correctly91./gradlew :compiler:build-tools:kotlin-build-tools-api-tests:testRestrictedArguments9293# Individual named test suites follow the pattern :test<SuiteName>94# The full list is in `businessLogicTestSuits` in kotlin-build-tools-api-tests/build.gradle.kts9596# Forward compatibility tests97./gradlew :compiler:build-tools:kotlin-build-tools-api-forward-tests:check98```99100## Writing Tests101102See [`kotlin-build-tools-api-tests/README.md`](kotlin-build-tools-api-tests/README.md) for full conventions. Key rules:103104- All tests extend `BaseTest` (`src/main/kotlin/BaseTest.kt`)105- All compilation tests extend `BaseCompilationTest` (`src/main/kotlin/compilation/BaseCompilationTest.kt`)106- Add `@DisplayName` to both test class and methods107- Add `@TestMetadata` pointing to the relevant test data directory for IDE navigation108- Keep test classes small — tests run in parallel109- Use the scenario DSL for incremental compilation tests; see `src/testExample/kotlin/ExampleIncrementalScenarioTest.kt`110- Annotate strategy-agnostic tests with `@DefaultStrategyAgnosticCompilationTest`111- Add a new test suite by appending its name to `businessLogicTestSuits` in `build.gradle.kts`112- Compatibility suites (`testCompatibility*`): add tests sparingly — they run once per listed version113114## Key Conventions and Pitfalls115116- Every public API addition in `kotlin-build-tools-api` must include KDoc documentation117- Do not add implementation dependencies to `kotlin-build-tools-api` — it must stay implementation-free118- Do not use `kotlin-build-tools-jdk-utils` outside BTA modules (requires `@KotlinBuildToolsInternalJdkUtils` opt-in)119- After changing compiler arguments, always regenerate both `generateBtaSources` and `apiDump`120
Also in JetBrains/kotlin
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| JetBrains/kotlincompiler/AGENTS.md · 53k | AGENTS.md | buildtestgit | 52/100 | 3 days ago | |
| JetBrains/kotlinCLAUDE.md · 53k | CLAUDE.md | agent-behaviour | 25/100 | 3 days ago | |
| JetBrains/kotlinanalysis/AGENTS.md · 53k | AGENTS.md | teststylearchapi+1 | 86/100 | 3 days ago | |
| JetBrains/kotlinanalysis/test-data-manager/AGENTS.md · 53k | AGENTS.md | teststylearchagent-behaviour | 66/100 | 3 days ago | |
| JetBrains/kotlincompiler/fir/analysis-tests/AGENTS.md · 53k | AGENTS.md | testlint-formatarchdeployment | 74/100 | 3 days ago | |
| JetBrains/kotlincompiler/psi/AGENTS.md · 53k | AGENTS.md | teststylearchtesting-strategy+3 | 81/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/inference/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+3 | 100/100 | 3 days ago | |
| react/react-nativepackages/react-native-compatibility-check/AGENTS.md · 126k | AGENTS.md | testlint-formatstylearch+4 | 99/100 | 3 days ago | |
| kurikomi-labs/komi-storeAGENTS.md · 17k | AGENTS.md | buildlint-formatstylearch+1 | 97/100 | 3 days ago | |
| tiann/KernelSUAGENTS.md · 18k | AGENTS.md | setupbuildlint-formatstyle+4 | 97/100 | 3 days ago | |
| elastic/elasticsearchAGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+6 | 96/100 | 3 days ago | |
| alibaba/nacosAGENTS.md · 33k | AGENTS.md | buildtestlint-formatstyle+6 | 96/100 | 3 days ago | |
| ktorio/ktorAGENTS.md · 14k | AGENTS.md | buildlint-formatstylearch+7 | 96/100 | 3 days ago |
