1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
plugins {
id("com.android.application")
}
android {
namespace = "org.the_jk.testproject"
compileSdk {
version = release(37)
}
defaultConfig {
applicationId = "org.the_jk.testproject"
minSdk = 26
targetSdk = 37
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
optimization {
enable = true
packageScope = setOf("androidx.**", "kotlin.**", "kotlinx.**")
}
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.espresso.core)
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.
//
// 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). The older `kotlinCompilerClasspath` still
// feeds the legacy path (kotlin.compiler.runViaBuildToolsApi=false,
// deprecated, removed in KGP 2.5.0). We shadow both.
val proxyStub = file("/home/the_jk/source/kotlin_proxy/dist/kotlin-proxy-compiler-stubs.jar")
val kotlinVersion = libs.versions.kotlin.get()
// legacy path: the kotlinCompilerClasspath default (kotlin-compiler-embeddable
// + its transitive deps). reflect stays at 1.6.10 - the POM pin.
val legacyCompilerJars = listOf(
"org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion",
"org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion",
"org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion",
"org.jetbrains.kotlin:kotlin-reflect:1.6.10",
"org.jetbrains.kotlin:kotlin-daemon-embeddable:$kotlinVersion",
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.8.0",
"org.jetbrains:annotations:13.0",
)
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"))
val cfg = configurations.getByName("kotlinCompilerClasspath")
cfg.dependencies.add(dependencies.create(files(proxyStub)))
legacyCompilerJars.forEach { cfg.dependencies.add(dependencies.create(it)) }
logger.lifecycle("kotlin-proxy: AGP stub present=" + proxyStub.exists() +
" BTA ORDER=" + bta.files.joinToString(",") { it.name })
} catch (t: Throwable) {
logger.lifecycle("kotlin-proxy: AGP injection FAILED: " + t)
}
}
|