Skip to content

Commit 8e3c6e8

Browse files
TapchicomaSpace Team
authored andcommitted
[Gradle] Don't suggest to apply Kotlin compose plugin for an AGP version above 8.5.0
AGP 8.5.0 has introduced the own suggestion to apply the required Kotlin compose compiler plugin. ^KT-69444 Verification Pending
1 parent 2583619 commit 8e3c6e8

File tree

2 files changed

+75
-1
lines changed
  • libraries/tools

2 files changed

+75
-1
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/ComposeIT.kt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,71 @@ class ComposeIT : KGPBaseTest() {
6666
}
6767
}
6868

69+
@DisplayName("Should conditionally suggest to migrate to new compose plugin")
70+
@AndroidTestVersions(
71+
maxVersion = TestVersions.AGP.AGP_86,
72+
additionalVersions = [TestVersions.AGP.AGP_85]
73+
)
74+
@AndroidGradlePluginTests
75+
@GradleAndroidTest
76+
@TestMetadata("AndroidSimpleApp")
77+
fun testAndroidComposeSuggestion(
78+
gradleVersion: GradleVersion,
79+
agpVersion: String,
80+
providedJdk: JdkVersions.ProvidedJdk
81+
) {
82+
project(
83+
projectName = "AndroidSimpleApp",
84+
gradleVersion = gradleVersion,
85+
buildJdk = providedJdk.location,
86+
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion)
87+
) {
88+
buildGradle.modify { originalBuildScript ->
89+
"""
90+
|$originalBuildScript
91+
|
92+
|dependencies {
93+
| implementation "androidx.compose.runtime:runtime:1.6.4"
94+
|}
95+
|
96+
|android.buildFeatures.compose = true
97+
|
98+
""".trimMargin()
99+
}
100+
101+
gradleProperties.appendText(
102+
"""
103+
android.useAndroidX=true
104+
""".trimIndent()
105+
)
106+
107+
buildAndFail("assembleDebug") {
108+
when (agpVersion) {
109+
TestVersions.AgpCompatibilityMatrix.AGP_71.version,
110+
TestVersions.AgpCompatibilityMatrix.AGP_72.version,
111+
TestVersions.AgpCompatibilityMatrix.AGP_73.version,
112+
TestVersions.AgpCompatibilityMatrix.AGP_74.version,
113+
TestVersions.AgpCompatibilityMatrix.AGP_80.version,
114+
TestVersions.AgpCompatibilityMatrix.AGP_81.version,
115+
TestVersions.AgpCompatibilityMatrix.AGP_82.version,
116+
TestVersions.AgpCompatibilityMatrix.AGP_83.version,
117+
TestVersions.AgpCompatibilityMatrix.AGP_84.version,
118+
-> {
119+
assertOutputContains(APPLY_COMPOSE_SUGGESTION)
120+
}
121+
else -> {
122+
// This error should come from AGP side
123+
assertOutputContains(
124+
"Starting in Kotlin 2.0, the Compose Compiler Gradle plugin is required\n" +
125+
" when compose is enabled. See the following link for more information:\n" +
126+
" https://d.android.com/r/studio-ui/compose-compiler\n"
127+
)
128+
}
129+
}
130+
}
131+
}
132+
}
133+
69134
@DisplayName("Should work correctly when compose in Android is enabled")
70135
@AndroidGradlePluginTests
71136
@GradleAndroidTest

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/diagnostics/checkers/ComposePluginSuggestApplyChecker.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.plugin.diagnostics.checkers
77

88
import org.gradle.api.Project
99
import org.gradle.api.plugins.PluginContainer
10+
import org.jetbrains.kotlin.gradle.plugin.AndroidGradlePluginVersion
1011
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
1112
import org.jetbrains.kotlin.gradle.plugin.diagnostics.*
1213
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinGradleProjectChecker
@@ -18,14 +19,20 @@ internal object ComposePluginSuggestApplyChecker : KotlinGradleProjectChecker {
1819
override suspend fun KotlinGradleProjectCheckerContext.runChecks(collector: KotlinToolingDiagnosticsCollector) {
1920
project.kotlinPluginLifecycle.await(KotlinPluginLifecycle.Stage.AfterFinaliseDsl)
2021

22+
// 'kotlin-android' project with AGP <8.5.0 where Compose enabled, but no Kotlin Compose Gradle plugin is used
2123
if (project.plugins.hasKotlinAndroidPlugin() &&
24+
!isAgp850AndAbove &&
2225
project.isAgpComposeEnabled &&
2326
!project.plugins.hasKotlinComposePlugin()
2427
) {
2528
collector.reportSuggestion(project)
26-
} else if (project.plugins.hasKotlinMultiplatformPlugin() &&
29+
} else if (
30+
// KMP project without Jetbrains Compose plugin, but with AGP <8.5.0 where Compose enabled,
31+
// and no Kotlin Compose Gradle plugin is used
32+
project.plugins.hasKotlinMultiplatformPlugin() &&
2733
!project.plugins.hasJetBrainsComposePlugin() &&
2834
project.isAgpComposeEnabled &&
35+
!isAgp850AndAbove &&
2936
!project.plugins.hasKotlinComposePlugin()
3037
) {
3138
collector.reportSuggestion(project)
@@ -55,4 +62,6 @@ internal object ComposePluginSuggestApplyChecker : KotlinGradleProjectChecker {
5562
private val Project.agpComposeConfiguration get() = configurations.findByName("kotlin-extension")
5663

5764
private val Project.isAgpComposeEnabled get() = agpComposeConfiguration != null
65+
66+
private val isAgp850AndAbove get() = AndroidGradlePluginVersion.current >= AndroidGradlePluginVersion(8, 5, 0)
5867
}

0 commit comments

Comments
 (0)