From 214140d7d14b540a3dff986b34ef17b99701cd60 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 6 Jul 2023 12:23:23 +0530 Subject: feat(build): automatically handle Compose Compiler compatibility override --- .../app/passwordstore/gradle/KotlinAndroidPlugin.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'build-logic/src/main') diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt index 46a5eb30..9e1641f3 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt @@ -8,10 +8,15 @@ package app.passwordstore.gradle import app.passwordstore.gradle.KotlinCommonPlugin.Companion.JVM_TOOLCHAIN_ACTION import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.api.artifacts.VersionCatalogsExtension +import org.gradle.api.artifacts.VersionConstraint import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @Suppress("Unused") class KotlinAndroidPlugin : Plugin { @@ -22,5 +27,19 @@ class KotlinAndroidPlugin : Plugin { apply(KotlinCommonPlugin::class) } project.extensions.getByType().jvmToolchain(JVM_TOOLCHAIN_ACTION) + val catalog = project.extensions.getByType() + val libs = catalog.named("libs") + if (libs.getVersion("composeCompiler").contains("-dev")) { + val kotlinVersion = libs.getVersion("kotlin") + project.tasks.withType().configureEach { + compilerOptions.freeCompilerArgs.addAll( + "-P", + "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=$kotlinVersion", + ) + } + } } + + private fun VersionCatalog.getVersion(key: String) = + findVersion(key).map(VersionConstraint::toString).get() } -- cgit v1.2.3