From b38ab2a7d610f9beaaf609c85185a258ad872f1f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 12 Jul 2024 15:27:04 -0700 Subject: [PATCH] Use K2 to compile buildSrc Make all Kotlin source code build with K2. K2 seems to have bugs with lazy property assignment, revert it to set(). --- buildSrc/build.gradle.kts | 8 ++++++++ buildSrc/src/main/java/Setup.kt | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 20cc2c684..9a5428dc1 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { `kotlin-dsl` } @@ -16,6 +18,12 @@ gradlePlugin { } } +tasks.withType().configureEach { + kotlinOptions { + languageVersion = "2.0" + } +} + dependencies { implementation(kotlin("gradle-plugin", "2.0.0")) implementation("com.android.tools.build:gradle:8.5.1") diff --git a/buildSrc/src/main/java/Setup.kt b/buildSrc/src/main/java/Setup.kt index 0bfb76aa5..ee587f0ce 100644 --- a/buildSrc/src/main/java/Setup.kt +++ b/buildSrc/src/main/java/Setup.kt @@ -308,7 +308,7 @@ fun Project.setupAppCommon() { this.comment = "version=${Config.version}\n" + "versionCode=${Config.versionCode}\n" + "stubVersion=${Config.stubVersion}\n" - this.outFolder = layout.buildDirectory.dir("outputs/apk/${variant.name}") + this.outFolder.set(layout.buildDirectory.dir("outputs/apk/${variant.name}")) } } } @@ -323,8 +323,8 @@ fun Project.setupStub() { project.tasks.register("${variantName}ManifestProducer", ManifestUpdater::class.java) { dependsOn("generate${variantCapped}ObfuscatedClass") applicationId = variant.applicationId - appClassDir = layout.buildDirectory.dir("generated/source/app/$variantName") - factoryClassDir = layout.buildDirectory.dir("generated/source/factory/$variantName") + appClassDir.set(layout.buildDirectory.dir("generated/source/app/$variantName")) + factoryClassDir.set(layout.buildDirectory.dir("generated/source/factory/$variantName")) } variant.artifacts.use(manifestUpdater) .wiredWithFiles(