Skip to content

Commit 87758dd

Browse files
TapchicomaSpace Cloud
authored and
Space Cloud
committed
[Gradle, Compose] Add diagnostic suggesting to apply new compose Gradle plugin
New diagnostic should only be active when Android Plugin compose is enabled, but the new Compose Gradle plugin is not applied. Also, this diagnostic is not active for the cases when JetBrains Compose plugin is applied, as JB Compose Gradle plugin provides the own suggestion. ^KT-67746 Verification Pending
1 parent 6d7fa73 commit 87758dd

File tree

21 files changed

+647
-0
lines changed

21 files changed

+647
-0
lines changed

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

+64
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle
88
import org.gradle.api.logging.LogLevel
99
import org.gradle.util.GradleVersion
1010
import org.jetbrains.kotlin.gradle.testbase.*
11+
import org.jetbrains.kotlin.test.TestMetadata
1112
import org.junit.jupiter.api.DisplayName
1213
import org.junit.jupiter.api.io.TempDir
1314
import java.nio.file.Path
@@ -20,6 +21,7 @@ class ComposeIT : KGPBaseTest() {
2021
@DisplayName("Should not affect Android project where compose is not enabled")
2122
@AndroidGradlePluginTests
2223
@GradleAndroidTest
24+
@TestMetadata("AndroidSimpleApp")
2325
fun testAndroidDisabledCompose(
2426
gradleVersion: GradleVersion,
2527
agpVersion: String,
@@ -51,6 +53,7 @@ class ComposeIT : KGPBaseTest() {
5153

5254
build("assembleDebug") {
5355
assertOutputDoesNotContain("Detected Android Gradle Plugin compose compiler configuration")
56+
assertOutputDoesNotContain(APPLY_COMPOSE_SUGGESTION)
5457
assertCompilerArgument(
5558
":compileDebugKotlin",
5659
"-P plugin:androidx.compose.compiler.plugins.kotlin:generateFunctionKeyMetaClasses=false," +
@@ -68,6 +71,7 @@ class ComposeIT : KGPBaseTest() {
6871
@DisplayName("Should work correctly when compose in Android is enabled")
6972
@AndroidGradlePluginTests
7073
@GradleAndroidTest
74+
@TestMetadata("AndroidSimpleComposeApp")
7175
fun testAndroidWithCompose(
7276
gradleVersion: GradleVersion,
7377
agpVersion: String,
@@ -81,13 +85,15 @@ class ComposeIT : KGPBaseTest() {
8185
) {
8286
build("assembleDebug") {
8387
assertOutputContains("Detected Android Gradle Plugin compose compiler configuration")
88+
assertOutputDoesNotContain(APPLY_COMPOSE_SUGGESTION)
8489
}
8590
}
8691
}
8792

8893
@DisplayName("Should not break build cache relocation")
8994
@AndroidGradlePluginTests
9095
@GradleAndroidTest
96+
@TestMetadata("AndroidSimpleComposeApp")
9197
fun testAndroidBuildCacheRelocation(
9298
gradleVersion: GradleVersion,
9399
agpVersion: String,
@@ -117,6 +123,59 @@ class ComposeIT : KGPBaseTest() {
117123
}
118124
}
119125

126+
@DisplayName("Should work with JB Compose plugin")
127+
@AndroidGradlePluginTests
128+
@GradleAndroidTest
129+
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_80)
130+
@TestMetadata("JBComposeApp")
131+
fun testJBCompose(
132+
gradleVersion: GradleVersion,
133+
agpVersion: String,
134+
providedJdk: JdkVersions.ProvidedJdk,
135+
) {
136+
project(
137+
projectName = "JBComposeApp",
138+
gradleVersion = gradleVersion,
139+
buildJdk = providedJdk.location,
140+
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion)
141+
) {
142+
build(":composeApp:assembleDebug") {
143+
assertOutputDoesNotContain("Detected Android Gradle Plugin compose compiler configuration")
144+
assertOutputDoesNotContain(APPLY_COMPOSE_SUGGESTION)
145+
}
146+
147+
build(":composeApp:desktopJar") {
148+
assertOutputDoesNotContain(APPLY_COMPOSE_SUGGESTION)
149+
}
150+
}
151+
}
152+
153+
@DisplayName("Should not suggest apply Kotlin compose plugin in JB Compose plugin")
154+
@AndroidGradlePluginTests
155+
@GradleAndroidTest
156+
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_80)
157+
@TestMetadata("JBComposeApp")
158+
fun testAndroidJBComposeNoSuggestion(
159+
gradleVersion: GradleVersion,
160+
agpVersion: String,
161+
providedJdk: JdkVersions.ProvidedJdk,
162+
) {
163+
project(
164+
projectName = "JBComposeApp",
165+
gradleVersion = gradleVersion,
166+
buildJdk = providedJdk.location,
167+
buildOptions = defaultBuildOptions.copy(androidVersion = agpVersion)
168+
) {
169+
subProject("composeApp").buildGradleKts.modify {
170+
it.replace("kotlin(\"plugin.compose\")", "")
171+
}
172+
173+
buildAndFail(":composeApp:assembleDebug") {
174+
assertOutputDoesNotContain(APPLY_COMPOSE_SUGGESTION)
175+
}
176+
}
177+
}
178+
120179
private fun androidComposeAppProjectWithLocalCacheEnabled(
121180
gradleVersion: GradleVersion,
122181
agpVersion: String,
@@ -154,4 +213,9 @@ class ComposeIT : KGPBaseTest() {
154213
enableLocalBuildCache(localCacheDir)
155214
}
156215
}
216+
217+
companion object {
218+
private const val APPLY_COMPOSE_SUGGESTION =
219+
"The Compose compiler plugin is now a part of Kotlin, please apply the 'org.jetbrains.kotlin.plugin.compose' Gradle plugin to enable it."
220+
}
157221
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2+
3+
plugins {
4+
id("com.android.application")
5+
kotlin("plugin.compose")
6+
kotlin("multiplatform")
7+
id("org.jetbrains.compose") version "1.6.10-beta03"
8+
}
9+
10+
kotlin {
11+
androidTarget {
12+
compilations.all {
13+
kotlinOptions {
14+
jvmTarget = "11"
15+
}
16+
}
17+
}
18+
19+
jvm("desktop")
20+
21+
sourceSets {
22+
val desktopMain by getting
23+
24+
androidMain.dependencies {
25+
implementation("androidx.compose.ui:ui-tooling-preview:1.6.6")
26+
implementation("androidx.activity:activity-compose:1.9.0")
27+
}
28+
commonMain.dependencies {
29+
implementation(compose.runtime)
30+
implementation(compose.foundation)
31+
implementation(compose.material)
32+
implementation(compose.ui)
33+
implementation(compose.components.resources)
34+
implementation(compose.components.uiToolingPreview)
35+
}
36+
desktopMain.dependencies {
37+
implementation(compose.desktop.currentOs)
38+
}
39+
}
40+
}
41+
42+
android {
43+
namespace = "org.example.project"
44+
compileSdk = 34
45+
46+
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
47+
sourceSets["main"].res.srcDirs("src/androidMain/res")
48+
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
49+
50+
defaultConfig {
51+
applicationId = "org.example.project"
52+
minSdk = 24
53+
targetSdk = 34
54+
versionCode = 1
55+
versionName = "1.0"
56+
}
57+
packaging {
58+
resources {
59+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
60+
}
61+
}
62+
buildTypes {
63+
getByName("release") {
64+
isMinifyEnabled = false
65+
}
66+
}
67+
compileOptions {
68+
sourceCompatibility = JavaVersion.VERSION_11
69+
targetCompatibility = JavaVersion.VERSION_11
70+
}
71+
dependencies {
72+
debugImplementation("androidx.compose.ui:ui-tooling:1.6.6")
73+
}
74+
}
75+
76+
compose.desktop {
77+
application {
78+
mainClass = "MainKt"
79+
80+
nativeDistributions {
81+
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
82+
packageName = "org.example.project"
83+
packageVersion = "1.0.0"
84+
}
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application
5+
android:allowBackup="true"
6+
android:icon="@drawable/ic_launcher_background"
7+
android:label="@string/app_name"
8+
android:supportsRtl="true"
9+
android:theme="@android:style/Theme.Material.Light.NoActionBar">
10+
<activity
11+
android:exported="true"
12+
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
13+
android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import android.os.Build
2+
3+
class AndroidPlatform : Platform {
4+
override val name: String = "Android ${Build.VERSION.SDK_INT}"
5+
}
6+
7+
actual fun getPlatform(): Platform = AndroidPlatform()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.example.project
2+
3+
import App
4+
import android.os.Bundle
5+
import androidx.activity.ComponentActivity
6+
import androidx.activity.compose.setContent
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.tooling.preview.Preview
9+
10+
class MainActivity : ComponentActivity() {
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
14+
setContent {
15+
App()
16+
}
17+
}
18+
}
19+
20+
@Preview
21+
@Composable
22+
fun AppAndroidPreview() {
23+
App()
24+
}

0 commit comments

Comments
 (0)