Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 884dd5d

Browse files
committed
fix(build): only suppress compat check for Compose Compiler when required
1 parent aab5130 commit 884dd5d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,28 @@ class KotlinAndroidPlugin : Plugin<Project> {
2929
project.extensions.getByType<KotlinProjectExtension>().jvmToolchain(JVM_TOOLCHAIN_ACTION)
3030
val catalog = project.extensions.getByType<VersionCatalogsExtension>()
3131
val libs = catalog.named("libs")
32-
if (libs.getVersion("composeCompiler").contains("-dev")) {
33-
val kotlinVersion = libs.getVersion("kotlin")
34-
project.tasks.withType<KotlinCompile>().configureEach {
35-
compilerOptions.freeCompilerArgs.addAll(
36-
"-P",
37-
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=$kotlinVersion",
38-
)
32+
val composeCompilerVersion = libs.getVersion("composeCompiler")
33+
val kotlinVersion = libs.getVersion("kotlin")
34+
val matches = COMPOSE_COMPILER_VERSION_REGEX.find(composeCompilerVersion)
35+
36+
if (matches != null) {
37+
val (compilerKotlinVersion) = matches.destructured
38+
if (compilerKotlinVersion != kotlinVersion) {
39+
project.tasks.withType<KotlinCompile>().configureEach {
40+
compilerOptions.freeCompilerArgs.addAll(
41+
"-P",
42+
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=$kotlinVersion",
43+
)
44+
}
3945
}
4046
}
4147
}
4248

4349
private fun VersionCatalog.getVersion(key: String) =
4450
findVersion(key).map(VersionConstraint::toString).get()
51+
52+
private companion object {
53+
// Matches against 1.5.0-dev-k1.9.0-6a60475e07f
54+
val COMPOSE_COMPILER_VERSION_REGEX = "\\d.\\d.\\d-dev-k(\\d.\\d.\\d)-[a-z0-9]+".toRegex()
55+
}
4556
}

0 commit comments

Comments
 (0)