Skip to content

Commit e7e8e12

Browse files
authored
Update KGP to 2.2 (#5293)
Compose gradle plugin now depends on Kotlin gradle plugin 2.2 ## Release Notes ### Migration Notes - Gradle Plugin - The compose gradle plugin requires Kotlin gradle plugin 2.+ version now. Old `org.jetbrains.compose.compiler` is not supported anymore and the API to configure it was removed.
1 parent 2e26cc1 commit e7e8e12

File tree

38 files changed

+399
-576
lines changed

38 files changed

+399
-576
lines changed

.github/workflows/gradle-plugin.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
os: [ubuntu-24.04, macos-14, windows-2022]
20-
gradle: [7.4, 8.13]
21-
agp: [8.6.0, 8.9.0]
19+
os: ['ubuntu-24.04', 'macos-14', 'windows-2022']
20+
gradle: ['8.7', '8.13']
21+
agp: ['8.6.0', '8.9.0']
2222
runs-on: ${{ matrix.os }}
2323
steps:
2424
- uses: actions/checkout@v4

gradle-plugins/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ subprojects {
3434
compilerOptions {
3535
// must be set to a language version of the kotlin compiler & runtime,
3636
// which is bundled to the oldest supported Gradle
37-
languageVersion.set(KotlinVersion.KOTLIN_1_6)
38-
apiVersion.set(KotlinVersion.KOTLIN_1_6)
37+
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
38+
languageVersion.set(KotlinVersion.KOTLIN_1_8)
39+
apiVersion.set(KotlinVersion.KOTLIN_1_8)
3940
jvmTarget.set(JvmTarget.JVM_11)
4041
}
4142
}

gradle-plugins/compose/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ val jar = tasks.named<Jar>("jar") {
9494

9595
val supportedGradleVersions = project.propertyList("compose.tests.gradle.versions")
9696
val supportedAgpVersions = project.propertyList("compose.tests.agp.versions")
97+
val excludedGradleAgpVersions = project.propertyList("compose.tests.gradle-agp.exclude")
9798

9899
fun Project.propertyList(name: String) =
99100
project.property(name).toString()
@@ -175,9 +176,8 @@ for (gradleVersion in supportedGradleVersions) {
175176
* > Failed to apply plugin 'com.android.internal.version-check'.
176177
* > Minimum supported Gradle version is 8.2. Current version is 7.4.
177178
*/
178-
val agpMajor = agpVersion.split('.').first().toInt()
179-
val gradleMajor = gradleVersion.split('.').first().toInt()
180-
onlyIf { agpMajor <= gradleMajor }
179+
val isExcluded = excludedGradleAgpVersions.contains("$gradleVersion/$agpVersion")
180+
onlyIf { !isExcluded }
181181

182182
systemProperty("compose.tests.gradle.test.jdks.root", jdkForTestsRoot.absolutePath)
183183
systemProperty("compose.tests.gradle.version", gradleVersion)
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")

0 commit comments

Comments
 (0)