Welcome! This file defines the mandatory workflow, engineering methodology, and project context for AI coding agents working in the Kotlin Symbol Processing (KSP) repository.
CONTRIBUTING.md First: Before proposing plans or modifying code, read CONTRIBUTING.md. It is the authoritative source for the bug contribution workflow (@Bug / BugState), api/api.base verification (checkApi / updateApi), and writing unit tests in kotlin-analysis-api.You are working on a compiler plugin and symbol processing engine. There must be zero speculation, hand-waving, or hallucination.
Resolver entry points to AnnotationResolutionStrategy / Analysis API session calls to KSNode / KSType wrappers to PSI / FIR symbols) and cite the concrete classes, functions, and line ranges involved.kotlin-analysis-api/testData and KSPUnitTestSuite.kt) or ask the user clarifying questions rather than guessing.README.md, CONTRIBUTING.md, DEVELOPMENT.md, AGENTS.md, or docs/) so that documentation never drifts out of sync with the implementation. This AGENTS.md file must also be kept in sync.LICENSE).CONTRIBUTING.md)..kt, .java) must include the standard Apache 2.0 license header used across the codebase:/* * Copyright <CURRENT YEAR> Google LLC * Copyright 2010-<CURRENT YEAR> JetBrains s.r.o. and Kotlin Programming Language contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
where <CURRENT YEAR> is the current year.
You will likely find files that do not have a copyright header. The headers may have been lost when moving the file in the editor. Do not restore those.
Important Note on KSP1: KSP 1.x has been removed and is no longer supported (
README.md). All active compiler engine development targets KSP2 (kotlin-analysis-api).
The project consists of Gradle subprojects configured in settings.gradle.kts:
| Module | Purpose & Key Details |
|---|---|
:api | Public-facing, dependency-free library (com.google.devtools.ksp:symbol-processing-api). Tracked by Metalava against api/api.base. |
:kotlin-analysis-api | Core KSP2 engine implemented on top of the Kotlin Analysis API (FIR/K2). Key entry points: KotlinSymbolProcessing.kt (src/main/kotlin/com/google/devtools/ksp/impl/), ResolverAAImpl.kt, AnnotationResolutionStrategy.kt (src/main/kotlin/com/google/devtools/ksp/common/impl/ with AAResolutionStrategy and PsiResolutionStrategy), all KS* symbol implementations (src/main/kotlin/com/google/devtools/ksp/impl/symbol/), and the primary unit test suite (KSPUnitTestSuite.kt). |
:symbol-processing-aa-embeddable | Repackages :kotlin-analysis-api and its dependencies into a self-contained uber-jar, relocating bundled packages under the ksp.* namespace (symbol-processing-aa-embeddable/build.gradle.kts) to avoid classpath conflicts. Entry point: KSPLoader.loadAndRunKSP(). |
:gradle-plugin | The KSP Gradle plugin (id("com.google.devtools.ksp"), KspGradleSubplugin in KspSubplugin.kt, and KspAATask.kt). Configures KSP tasks for JVM, Android, and Kotlin Multiplatform (KMP) projects. |
:common-util | Shared internal utilities used by :kotlin-analysis-api and other modules. |
:common-deps | Shared dependencies and command-line argument parsing utilities (symbol-processing-common-deps). Uses :cmdline-parser-gen via KSP. |
:cmdline-parser-gen | Internal KSP processor used during the build to generate command-line parser code for :common-deps. |
:integration-tests | End-to-end Gradle TestKit tests validating the published KSP uber-jar and Gradle plugin across real build scenarios (primaryTest, secondaryTest, androidTest, agpTest). |
:symbol-processing | Dummy POM-only artifact maintained for KotlinCompilerPluginSupportPlugin compatibility. |
:test-utils | Legacy test utilities. Deprecated for new unit tests (CONTRIBUTING.md)—all new unit tests belong in :kotlin-analysis-api. |
Read CONTRIBUTING.md.
gradle.properties & gradle/libs.versions.toml):buildKotlinVersion / buildKspVersion: Used in gradle.properties to bootstrap and compile the KSP project itself.kotlinBaseVersion (kotlin-base) & agpBaseVersion (agp-base): Duplicated in both gradle.properties and gradle/libs.versions.toml. gradle-plugin's TestConfig loads gradle.properties directly at test runtime—always keep both files in sync.aa-kotlin-base (aaKotlinBaseVersion): The specific (often developmental) Kotlin version used for Analysis API dependencies in :kotlin-analysis-api and :symbol-processing-aa-embeddable.Note: Because
KSPUnitTestSuiteisabstract, use a wildcard or a concrete subclass name with--tests:
./gradlew :kotlin-analysis-api:test --tests "*.<testMethodName>"
./gradlew :kotlin-analysis-api:test
Metalava): Whenever modifying public declarations in :api, verify compatibility against api/api.base:./gradlew :api:checkApi ./gradlew :api:updateApi
./gradlew :kotlin-analysis-api:validateShadowJar: Runs jdeps against kotlin-analysis-api/shadow-validation-baseline.txt and verifies no forbidden packages (such as org/apache/log4j/jdbc) leak into the shadow JAR../gradlew :symbol-processing-aa-embeddable:shadowJar: Verifies that all bundled classes are relocated into allowed ksp.* namespaces../gradlew :gradle-plugin:test: Runs tests for the KSP Gradle plugin.<rootProject>/build/repos/test and run Gradle TestKit suites (integration-tests/build.gradle.kts):./gradlew :integration-tests:primaryTest ./gradlew :integration-tests:secondaryTest ./gradlew :integration-tests:androidTest ./gradlew :integration-tests:agpTestIntegration tests may take a long time to run so it may be helpful to just run a single test or test class when making changes, e.g.,
./gradlew :integration-tests:primaryTest --tests "com.google.devtools.ksp.test.primary.<TestClass>.<method>"where
TestClass is the name of the class containing tests and method is the name of test method/entrypoint../gradlew check task and check that it completes successfully.Note: It may be necessary to pass
--rerun-tasksto ensure cached test or task outputs are re-evaluated after changes.
./gradlew check --rerun-tasks