summaryrefslogtreecommitdiff
path: root/CLAUDE.md
diff options
context:
space:
mode:
Diffstat (limited to 'CLAUDE.md')
-rw-r--r--CLAUDE.md48
1 files changed, 35 insertions, 13 deletions
diff --git a/CLAUDE.md b/CLAUDE.md
index 63fa5d8..bdaa44c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -163,19 +163,41 @@ re-verifying, and `rm /tmp/kotlin-proxy-marker.txt` for a fresh marker.
logging+null (the daemon dispatches through bridges).
- **Classpath shadowing (the subtle part):** KGP ≥ 2.3.20 runs JVM compilation
through the **Build Tools API** by default, and the daemon's JVM classpath is
- the resolved **`kotlinBuildToolsApiClasspath`** configuration (default deps:
- `kotlin-build-tools-compat` + `kotlin-build-tools-impl`, whose transitive
- closure *is* the compiler). Like any `defaultDependencies`-seeded
- configuration, adding *any* regular dependency suppresses the defaults — so
- `test_project/app/build.gradle.kts` re-declares the stub jar **first** plus
- those two modules as regular deps, and the daemon loads `K2JVMCompiler`
- from the stub. The older `kotlinCompilerClasspath` (legacy
- `runViaBuildToolsApi=false` path, deprecated, removed in KGP 2.5) is shadowed
- the same way for completeness. The root `build.gradle.kts` also puts the stub
- first on the *buildscript* classpath, and pins KGP explicitly — AGP 9.x's
- built-in Kotlin would otherwise apply its own pinned KGP version (AGP 9.0
- release notes, "Runtime dependency on Kotlin Gradle plugin").
- All intentional.
+ the resolved **`kotlinBuildToolsApiClasspath`** configuration (KGP seeds it
+ with *regular* deps `kotlin-build-tools-compat` + `kotlin-build-tools-impl`,
+ whose transitive closure *is* the compiler — verified on KGP 2.4.21, where
+ `config.dependencies` shows exactly those two plus our file dep; the old
+ `defaultDependencies` story is stale, and Gradle 9 removed
+ `defaultDependencies` from `Configuration` entirely).
+ `test_project/app/build.gradle.kts` therefore adds **only** the stub jar as
+ a `files(...)` dep (in `afterEvaluate`); Gradle resolves **file-collection
+ deps before module deps**, so the stub lands FIRST in the resolved file
+ order (observed on the daemon's `--daemon-compilerClasspath`) and the daemon
+ loads `K2JVMCompiler` from the stub — no re-declaration of compat/impl.
+ Do NOT resolve the configuration at configuration time (no
+ `Configuration.files` / `.incoming` access in `afterEvaluate` or earlier):
+ AGP's `DependencyResolutionChecks` raises "Configuration
+ 'kotlinBuildToolsApiClasspath' was resolved during configuration time".
+ Declaring a dependency does not resolve — resolution happens at execution
+ time when the compile task runs.
+ The legacy `kotlinCompilerClasspath` (`runViaBuildToolsApi=false` path,
+ removed in KGP 2.5) carries no deps in this setup and is left alone.
+ The root `build.gradle.kts` also puts the stub first on the *buildscript*
+ classpath, and pins KGP explicitly — AGP 9.x's built-in Kotlin would
+ otherwise apply its own pinned KGP version (AGP 9.0 release notes, "Runtime
+ dependency on Kotlin Gradle plugin"). All intentional.
+- **Why not a `-javaagent` instead (explored, not adopted):** the daemon JVM
+ args channel works in this flow — the Gradle property
+ **`kotlin.daemon.jvmargs`** (NOT the legacy `kotlin.daemon.jvm.options`)
+ reaches the daemon's command line, so a `-javaagent` jar is loaded in the
+ daemon and its `ClassFileTransformer` successfully swaps the
+ `K2JVMCompiler` trio's bytes. But a transformer is only consulted for class
+ files the classloader can actually *find* — it replaces, it cannot ADD.
+ The stubs reference `kotlin.proxy.*` support classes that exist nowhere on
+ the daemon's classpath, so a swapped `K2JVMCompiler` dies with
+ `ClassNotFoundException: kotlin.proxy.KotlinProxyLog`. The agent route
+ would need fully self-contained stubs (the `kotlin.proxy.*` logic inlined
+ into the trio by `gen_class.py`) before it becomes viable.
## Gotchas