fix(build): only suppress compat check for Compose Compiler when required

This commit is contained in:
Harsh Shandilya 2023-07-07 12:08:50 +05:30
parent aab513060b
commit 884dd5dee9
No known key found for this signature in database

View file

@ -29,8 +29,13 @@ class KotlinAndroidPlugin : Plugin<Project> {
project.extensions.getByType<KotlinProjectExtension>().jvmToolchain(JVM_TOOLCHAIN_ACTION) project.extensions.getByType<KotlinProjectExtension>().jvmToolchain(JVM_TOOLCHAIN_ACTION)
val catalog = project.extensions.getByType<VersionCatalogsExtension>() val catalog = project.extensions.getByType<VersionCatalogsExtension>()
val libs = catalog.named("libs") val libs = catalog.named("libs")
if (libs.getVersion("composeCompiler").contains("-dev")) { val composeCompilerVersion = libs.getVersion("composeCompiler")
val kotlinVersion = libs.getVersion("kotlin") 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<KotlinCompile>().configureEach { project.tasks.withType<KotlinCompile>().configureEach {
compilerOptions.freeCompilerArgs.addAll( compilerOptions.freeCompilerArgs.addAll(
"-P", "-P",
@ -39,7 +44,13 @@ class KotlinAndroidPlugin : Plugin<Project> {
} }
} }
} }
}
private fun VersionCatalog.getVersion(key: String) = private fun VersionCatalog.getVersion(key: String) =
findVersion(key).map(VersionConstraint::toString).get() 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()
}
} }