Browse Source

[gradle] Set custom freeCompilerArgs only for the old compiler plugin. (#5129)

Fixes https://youtrack.jetbrains.com/issue/CMP-5835

## Release Notes
### Fixes - Gradle Plugin
- Fix a gradle project misconfiguration when KSP and Room are used.
release/1.7.0-beta02
Konstantin 3 months ago committed by GitHub
parent
commit
a15798db40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 32
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerKotlinSupportPlugin.kt
  2. 37
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt

32
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerKotlinSupportPlugin.kt

@ -14,7 +14,9 @@ import org.jetbrains.compose.internal.KOTLIN_JVM_PLUGIN_ID
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
import org.jetbrains.compose.internal.Version
import org.jetbrains.compose.internal.ideaIsInSyncProvider
import org.jetbrains.compose.internal.mppExtOrNull
import org.jetbrains.compose.internal.webExt
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
@ -52,6 +54,32 @@ private fun Project.configureComposeCompilerPlugin(kgp: KotlinBasePlugin) {
if (Version.fromString(kgpVersion) < Version.fromString(newCompilerIsAvailableVersion)) {
logger.info("Apply ComposeCompilerKotlinSupportPlugin (KGP version = $kgpVersion)")
project.plugins.apply(ComposeCompilerKotlinSupportPlugin::class.java)
//legacy logic applied for Kotlin < 2.0 only
project.afterEvaluate {
val composeExtension = project.extensions.getByType(ComposeExtension::class.java)
project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile::class.java).configureEach {
it.kotlinOptions.apply {
freeCompilerArgs = freeCompilerArgs +
composeExtension.kotlinCompilerPluginArgs.get().flatMap { arg ->
listOf("-P", "plugin:androidx.compose.compiler.plugins.kotlin:$arg")
}
}
}
val hasAnyWebTarget = project.mppExtOrNull?.targets?.firstOrNull {
it.platformType == KotlinPlatformType.js ||
it.platformType == KotlinPlatformType.wasm
} != null
if (hasAnyWebTarget) {
// currently k/wasm compile task is covered by KotlinJsCompile type
project.tasks.withType(KotlinJsCompile::class.java).configureEach {
it.kotlinOptions.freeCompilerArgs += listOf(
"-Xklib-enable-signature-clash-checks=false",
)
}
}
}
} else {
//There is no other way to check that the plugin WASN'T applied!
afterEvaluate {
@ -76,8 +104,8 @@ class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {
val composeExt = target.extensions.getByType(ComposeExtension::class.java)
composeCompilerArtifactProvider = ComposeCompilerArtifactProvider {
composeExt.kotlinCompilerPlugin.orNull ?:
ComposeCompilerCompatibility.compilerVersionFor(target.getKotlinPluginVersion())
composeExt.kotlinCompilerPlugin.orNull
?: ComposeCompilerCompatibility.compilerVersionFor(target.getKotlinPluginVersion())
}
applicableForPlatformTypes = composeExt.platformTypes

37
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt

@ -19,17 +19,16 @@ import org.jetbrains.compose.desktop.DesktopExtension
import org.jetbrains.compose.desktop.application.internal.configureDesktop
import org.jetbrains.compose.desktop.preview.internal.initializePreview
import org.jetbrains.compose.experimental.dsl.ExperimentalExtension
import org.jetbrains.compose.experimental.internal.*
import org.jetbrains.compose.internal.*
import org.jetbrains.compose.experimental.internal.configureExperimentalTargetsFlagsCheck
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
import org.jetbrains.compose.internal.mppExt
import org.jetbrains.compose.internal.utils.currentTarget
import org.jetbrains.compose.resources.ResourcesExtension
import org.jetbrains.compose.resources.configureComposeResources
import org.jetbrains.compose.web.WebExtension
import org.jetbrains.compose.web.internal.configureWeb
import org.jetbrains.kotlin.com.github.gundy.semver4j.SemVer
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
internal val composeVersion get() = ComposeBuildConfig.composeVersion
@ -61,32 +60,6 @@ abstract class ComposePlugin : Plugin<Project> {
val mppExt = project.mppExt
project.configureExperimentalTargetsFlagsCheck(mppExt)
}
project.tasks.withType(KotlinCompile::class.java).configureEach {
it.kotlinOptions.apply {
freeCompilerArgs = freeCompilerArgs +
composeExtension.kotlinCompilerPluginArgs.get().flatMap { arg ->
listOf("-P", "plugin:androidx.compose.compiler.plugins.kotlin:$arg")
}
}
}
disableSignatureClashCheck(project)
}
}
private fun disableSignatureClashCheck(project: Project) {
val hasAnyWebTarget = project.mppExtOrNull?.targets?.firstOrNull {
it.platformType == KotlinPlatformType.js ||
it.platformType == KotlinPlatformType.wasm
} != null
if (hasAnyWebTarget) {
// currently k/wasm compile task is covered by KotlinJsCompile type
project.tasks.withType(KotlinJsCompile::class.java).configureEach {
it.kotlinOptions.freeCompilerArgs += listOf(
"-Xklib-enable-signature-clash-checks=false",
)
}
}
}

Loading…
Cancel
Save