From 854788d8824fceaf0ce45045a56150e0bc92f2ee Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 16 Nov 2026 20:56:28 +0100 Subject: Cleanup stub file injection --- test_project/app/build.gradle.kts | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'test_project/app') diff --git a/test_project/app/build.gradle.kts b/test_project/app/build.gradle.kts index b106e73..b5da6e1 100644 --- a/test_project/app/build.gradle.kts +++ b/test_project/app/build.gradle.kts @@ -41,29 +41,24 @@ dependencies { androidTestImplementation(libs.androidx.junit) } -// ---- kotlin-proxy: force our compiler stub to the FRONT of the daemon classpath ---- -// KGP seeds the daemon classpath with hidden defaultDependencies; adding ANY -// regular dependency suppresses those defaults - so we re-declare the same -// modules as regular deps WITH our stub jar FIRST. The daemon then loads -// org.jetbrains.kotlin.cli.jvm.K2JVMCompiler from OUR stub, replacing the -// real compiler with our alternative. +// kotlin-proxy: shadow the Kotlin compiler in the compile DAEMON by putting +// the stub jar FIRST on its classpath (the kotlinBuildToolsApiClasspath +// configuration, whose resolved file order becomes the daemon's -cp). // -// KGP >= 2.3.20 runs JVM compilation through the Build Tools API by default: -// the daemon classpath is the resolved `kotlinBuildToolsApiClasspath` -// (defaults: kotlin-build-tools-compat + kotlin-build-tools-impl, whose -// closure IS the compiler). -val proxyStub = file("/home/the_jk/source/kotlin_proxy/dist/kotlin-proxy-compiler-stubs.jar") -val kotlinVersion = libs.versions.kotlin.get() +// KGP adds kotlin-build-tools-compat/-impl to this configuration itself, so +// only the stub jar needs to be declared here - first, to win the lookup. +// +// Deliberately NO configuration-time resolution (no Configuration.files / +// .incoming access): AGP's DependencyResolutionChecks raises +// "was resolved during configuration time" for that. Declaring a dependency +// does not resolve; resolution happens at execution time when the compile +// task runs. +val proxyStubJar = file("/home/the_jk/source/kotlin_proxy/dist/kotlin-proxy-compiler-stubs.jar") afterEvaluate { try { - val bta = configurations.getByName("kotlinBuildToolsApiClasspath") - bta.dependencies.add(dependencies.create(files(proxyStub))) - bta.dependencies.add(dependencies.create( - "org.jetbrains.kotlin:kotlin-build-tools-compat:$kotlinVersion")) - bta.dependencies.add(dependencies.create( - "org.jetbrains.kotlin:kotlin-build-tools-impl:$kotlinVersion")) - logger.lifecycle("kotlin-proxy: AGP stub present=" + proxyStub.exists() + - " BTA ORDER=" + bta.files.joinToString(",") { it.name }) + configurations.getByName("kotlinBuildToolsApiClasspath") + .dependencies.add(dependencies.create(files(proxyStubJar))) + logger.lifecycle("kotlin-proxy: stub jar present=" + proxyStubJar.exists()) } catch (t: Throwable) { logger.lifecycle("kotlin-proxy: AGP injection FAILED: " + t) } -- cgit v1.3.1