Skip to content

Commit

Permalink
Add a warning for a user who sets compose.kotlinCompilerPlugin to `…
Browse files Browse the repository at this point in the history
…android.compose.compiler.compiler`

The warning will show up only when a multiplatform project contains at least one of the non-jvm targets: k/js, k/native or k/wasm
  • Loading branch information
eymar committed Jul 5, 2023
1 parent 2335739 commit 63efd60
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.compose
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.jetbrains.compose.internal.ComposeCompilerArtifactProvider
import org.jetbrains.compose.internal.mppExt
import org.jetbrains.compose.internal.webExt
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
Expand All @@ -25,6 +26,23 @@ class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {
ComposeCompilerCompatibility.compilerVersionFor(target.getKotlinPluginVersion())
}
}
warnAboutJetpackComposeCompilerUsageForNonJvm(target)
}

@Suppress("NON_EXHAUSTIVE_WHEN")
private fun warnAboutJetpackComposeCompilerUsageForNonJvm(target: Project) {
val isUsingJetpackComposeCompilerPlugin =
composeCompilerArtifactProvider.compilerArtifact.groupId.startsWith("androidx.compose.compiler")

if (isUsingJetpackComposeCompilerPlugin) {
target.mppExt.targets.forEach {
when (it.platformType) {
KotlinPlatformType.native,
KotlinPlatformType.js,
KotlinPlatformType.wasm -> target.logger.warn(WARN_ABOUT_JC_COMPILER)
}
}
}
}

override fun getCompilerPluginId(): String =
Expand Down Expand Up @@ -68,4 +86,15 @@ class ComposeCompilerKotlinSupportPlugin : KotlinCompilerPluginSupportPlugin {

private fun options(vararg options: Pair<String, String>): List<SubpluginOption> =
options.map { SubpluginOption(it.first, it.second) }
}
}

private const val COMPOSE_COMPILER_COMPATIBILITY_LINK =
"https://github.com/JetBrains/compose-jb/blob/master/VERSIONING.md"

private val WARN_ABOUT_JC_COMPILER = """
| WARNING: You are using the 'androidx.compose.compiler' plugin in your Kotlin multiplatform project.
| This plugin is only guaranteed to work with JVM targets (desktop or Android).
| The usage with Kotlin/JS or Kotlin/Native targets is not supported and might cause issues.
| Make sure you are using compatible versions of the Jetpack Compose Compiler and Kotlin.
| You can find the compatibility table here: $COMPOSE_COMPILER_COMPATIBILITY_LINK
""".trimMargin()

0 comments on commit 63efd60

Please sign in to comment.