From 884dd5dee9d72188416cda535f9731047f4ae96b Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 7 Jul 2023 12:08:50 +0530 Subject: fix(build): only suppress compat check for Compose Compiler when required --- .../passwordstore/gradle/KotlinAndroidPlugin.kt | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'build-logic/src/main/kotlin/app') 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 9e1641f3..a80a5807 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt @@ -29,17 +29,28 @@ class KotlinAndroidPlugin : Plugin { 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", - ) + val composeCompilerVersion = libs.getVersion("composeCompiler") + val kotlinVersion = libs.getVersion("kotlin") + val matches = COMPOSE_COMPILER_VERSION_REGEX.find(composeCompilerVersion) + + if (matches != null) { + val (compilerKotlinVersion) = matches.destructured + if (compilerKotlinVersion != kotlinVersion) { + 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() + + private companion object { + // Matches against 1.5.0-dev-k1.9.0-6a60475e07f + val COMPOSE_COMPILER_VERSION_REGEX = "\\d.\\d.\\d-dev-k(\\d.\\d.\\d)-[a-z0-9]+".toRegex() + } } -- cgit v1.2.3