From af2f2b2b8de7378b8619d28879b1434d63c24dcd Mon Sep 17 00:00:00 2001 From: Oleksandr Karpovich Date: Tue, 27 Jul 2021 09:57:27 +0200 Subject: [PATCH] Add a check that compose is used along with kotlinx.serialization (#900) * Add a check that compose is used along with kotlinx.serialization There's a known issue that both plugins can't be used in the same module (specifically for kotlin/js targets). The compose gradle plugin will check for `kotlinx.serialization` and will show a warning. * Fix PR suggestions * Update WarnAboutComposeWithSerialization.kt Update the link for the issue Co-authored-by: Oleksandr Karpovich --- .../org/jetbrains/compose/ComposePlugin.kt | 3 +++ .../WarnAboutComposeWithSerialization.kt | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/WarnAboutComposeWithSerialization.kt diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt index a0c990d3ff..90bc913107 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt @@ -16,6 +16,7 @@ import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.application.internal.configureApplicationImpl import org.jetbrains.compose.desktop.application.internal.currentTarget import org.jetbrains.compose.desktop.preview.internal.initializePreview +import org.jetbrains.compose.internal.checkAndWarnAboutComposeWithSerialization import org.jetbrains.compose.web.internal.initializeWeb import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -106,6 +107,8 @@ class ComposePlugin : Plugin { useIR = true } } + + project.checkAndWarnAboutComposeWithSerialization() } object Dependencies { diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/WarnAboutComposeWithSerialization.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/WarnAboutComposeWithSerialization.kt new file mode 100644 index 0000000000..8ca6c7f2e9 --- /dev/null +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/WarnAboutComposeWithSerialization.kt @@ -0,0 +1,18 @@ +package org.jetbrains.compose.internal + +import org.gradle.api.Project + +internal fun Project.checkAndWarnAboutComposeWithSerialization() { + project.plugins.withId("org.jetbrains.kotlin.plugin.serialization") { + val warningMessage = """ + + >>> COMPOSE WARNING + >>> Project `${project.name}` has `compose` and `kotlinx.serialization` plugins applied! + >>> Consider using these plugins in separate modules to avoid compilation errors + >>> Check more details here: https://github.com/JetBrains/compose-jb/issues/738 + + """.trimIndent() + + logger.warn(warningMessage) + } +}