Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a warning for a user who sets compose.kotlinCompilerPlugin to androidx.compose.compiler.compiler #3313

Merged
merged 5 commits into from
Jul 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
igordmn marked this conversation as resolved.
Show resolved Hide resolved
}

@Suppress("NON_EXHAUSTIVE_WHEN")
private fun warnAboutJetpackComposeCompilerUsageForNonJvm(target: Project) {
val isUsingJetpackComposeCompilerPlugin =
composeCompilerArtifactProvider.compilerArtifact.groupId.startsWith("androidx.compose.compiler")
igordmn marked this conversation as resolved.
Show resolved Hide resolved

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.
igordmn marked this conversation as resolved.
Show resolved Hide resolved
eymar marked this conversation as resolved.
Show resolved Hide resolved
| 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()