Skip to content

Commit cdb0b87

Browse files
committed
Remove legacy Compose compiler plugin handling
Replaced legacy handling of the Compose compiler plugin with a new mechanism using `checkComposeCompilerPlugin`. This ensures compatibility with Kotlin 2.0.0+ and eliminates outdated compatibility code, simplifying future maintenance.
1 parent 4869b4a commit cdb0b87

File tree

5 files changed

+59
-213
lines changed

5 files changed

+59
-213
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package org.jetbrains.compose
7+
8+
import org.gradle.api.Project
9+
import org.jetbrains.compose.internal.KOTLIN_ANDROID_PLUGIN_ID
10+
import org.jetbrains.compose.internal.KOTLIN_JS_PLUGIN_ID
11+
import org.jetbrains.compose.internal.KOTLIN_JVM_PLUGIN_ID
12+
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
13+
import org.jetbrains.compose.internal.Version
14+
import org.jetbrains.compose.internal.ideaIsInSyncProvider
15+
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
16+
17+
internal fun Project.checkComposeCompilerPlugin() {
18+
//only one of them can be applied to the project
19+
listOf(
20+
KOTLIN_MPP_PLUGIN_ID,
21+
KOTLIN_JVM_PLUGIN_ID,
22+
KOTLIN_ANDROID_PLUGIN_ID,
23+
KOTLIN_JS_PLUGIN_ID
24+
).forEach { pluginId ->
25+
plugins.withId(pluginId) { plugin ->
26+
checkComposeCompilerPlugin(plugin as KotlinBasePlugin)
27+
}
28+
}
29+
}
30+
31+
internal const val minimalSupportedKgpVersionError = "e: Configuration problem: " +
32+
"Minimal supported Kotlin Gradle Plugin version is 2.0.0"
33+
internal const val newCompilerIsAvailableVersion = "2.0.0"
34+
internal const val newComposeCompilerKotlinSupportPluginId = "org.jetbrains.kotlin.plugin.compose"
35+
internal const val newComposeCompilerError =
36+
"Since Kotlin 2.0.0 to use Compose Multiplatform " +
37+
"you must apply \"$newComposeCompilerKotlinSupportPluginId\" plugin." +
38+
"\nSee the migration guide https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compiler.html#migrating-a-compose-multiplatform-project"
39+
40+
private fun Project.checkComposeCompilerPlugin(kgp: KotlinBasePlugin) {
41+
val kgpVersion = kgp.pluginVersion
42+
val ideaIsInSync = project.ideaIsInSyncProvider().get()
43+
44+
if (Version.fromString(kgpVersion) < Version.fromString(newCompilerIsAvailableVersion)) {
45+
if (ideaIsInSync) logger.error(minimalSupportedKgpVersionError)
46+
else error(minimalSupportedKgpVersionError)
47+
} else {
48+
//There is no other way to check that the plugin WASN'T applied!
49+
afterEvaluate {
50+
logger.info("Check that new '$newComposeCompilerKotlinSupportPluginId' was applied")
51+
if (!project.plugins.hasPlugin(newComposeCompilerKotlinSupportPluginId)) {
52+
if (ideaIsInSync) logger.error("e: Configuration problem: $newComposeCompilerError")
53+
else error("e: Configuration problem: $newComposeCompilerError")
54+
}
55+
}
56+
}
57+
}

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

Lines changed: 0 additions & 43 deletions
This file was deleted.

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

Lines changed: 0 additions & 156 deletions
This file was deleted.

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.jetbrains.compose.resources.configureComposeResources
2828
import org.jetbrains.compose.web.WebExtension
2929
import org.jetbrains.compose.web.internal.configureWeb
3030
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
31-
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
3231

3332
internal val composeVersion get() = ComposeBuildConfig.composeVersion
3433

@@ -49,7 +48,7 @@ abstract class ComposePlugin : Plugin<Project> {
4948
project.initializePreview(desktopExtension)
5049
composeExtension.extensions.create("web", WebExtension::class.java)
5150

52-
project.configureComposeCompilerPlugin()
51+
project.checkComposeCompilerPlugin()
5352

5453
project.configureComposeResources(resourcesExtension)
5554

@@ -66,7 +65,6 @@ abstract class ComposePlugin : Plugin<Project> {
6665
@Suppress("DEPRECATION")
6766
class Dependencies(project: Project) {
6867
val desktop = DesktopDependencies
69-
val compiler = CompilerDependencies(project)
7068
val animation get() = composeDependency("org.jetbrains.compose.animation:animation")
7169
val animationGraphics get() = composeDependency("org.jetbrains.compose.animation:animation-graphics")
7270
val foundation get() = composeDependency("org.jetbrains.compose.foundation:foundation")
@@ -109,16 +107,6 @@ abstract class ComposePlugin : Plugin<Project> {
109107
}
110108
}
111109

112-
class CompilerDependencies(private val project: Project) {
113-
fun forKotlin(version: String) = "org.jetbrains.compose.compiler:compiler:" +
114-
ComposeCompilerCompatibility.compilerVersionFor(version)
115-
116-
/**
117-
* Compose Compiler that is chosen by the version of Kotlin applied to the Gradle project
118-
*/
119-
val auto get() = forKotlin(project.getKotlinPluginVersion())
120-
}
121-
122110
object CommonComponentsDependencies {
123111
val resources = composeDependency("org.jetbrains.compose.components:components-resources")
124112
val uiToolingPreview = composeDependency("org.jetbrains.compose.components:components-ui-tooling-preview")

gradle-plugins/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ kotlin.code.style=official
88
dev.junit.parallel=false
99

1010
# Default version of Compose Libraries used by Gradle plugin
11-
compose.version=1.8.10+dev2320
11+
compose.version=1.8.10+dev2347
1212
# The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI.
1313
compose.tests.kotlin.version=2.2.0-Beta1
1414
# __SUPPORTED_GRADLE_VERSIONS__

0 commit comments

Comments
 (0)