-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bundle Compose Hot Reload Gradle plugin into the Compose Gradle plugin #5444
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.jetbrains.compose.test.tests.integration | ||
|
||
import org.gradle.testkit.runner.BuildResult | ||
import org.jetbrains.compose.ComposeBuildConfig | ||
import org.jetbrains.compose.test.utils.GradlePluginTestBase | ||
import org.jetbrains.compose.test.utils.checks | ||
import org.jetbrains.compose.test.utils.modify | ||
import org.junit.jupiter.api.Test | ||
import kotlin.concurrent.thread | ||
|
||
class HotReloadTest : GradlePluginTestBase() { | ||
@Test | ||
fun smokeTestHotRunTask() = with(testProject("application/jvm")) { | ||
file("build.gradle").modify { | ||
it + """ | ||
afterEvaluate { | ||
tasks.getByName("hotRun").doFirst { | ||
throw new StopExecutionException("Skip hotRun task") | ||
} | ||
} | ||
""".trimIndent() | ||
} | ||
gradle("hotRun").checks { | ||
check.taskSuccessful(":hotRun") | ||
} | ||
} | ||
|
||
@Test | ||
fun testHotReload() = with(testProject("application/hotReload")) { | ||
var result: BuildResult? = null | ||
val hotRunThread = thread { | ||
result = gradle("hotRunJvm") | ||
} | ||
|
||
while (!file("started").exists()) { | ||
Thread.sleep(200) | ||
} | ||
|
||
modifyText("src/jvmMain/kotlin/main.kt") { | ||
it.replace("Kotlin MPP", "KMP") | ||
} | ||
|
||
gradle("reload").checks { | ||
check.taskSuccessful(":reload") | ||
check.logContains("MainKt.class: modified") | ||
} | ||
|
||
hotRunThread.join() | ||
check(result != null) | ||
result.checks { | ||
check.taskSuccessful(":hotRunJvm") | ||
check.logContains("Kotlin MPP app is running!") | ||
check.logContains("KMP app is running!") | ||
check.logContains("Compose Hot Reload (${ComposeBuildConfig.composeHotReloadVersion})") | ||
} | ||
} | ||
|
||
@Test | ||
fun testExternalHotReload() = with(testProject("application/mpp")) { | ||
val externalHotReloadVersion = "1.0.0-beta04" | ||
modifyText("settings.gradle") { | ||
it.replace( | ||
"plugins {", "plugins {\n" + | ||
""" | ||
id 'org.jetbrains.compose.hot-reload' version '$externalHotReloadVersion' | ||
""".trimIndent() | ||
) | ||
} | ||
modifyText("build.gradle") { | ||
it.replace( | ||
"plugins {", "plugins {\n" + | ||
""" | ||
id "org.jetbrains.compose.hot-reload" | ||
""".trimIndent() | ||
) | ||
} | ||
gradle("hotRunJvm").checks { | ||
check.taskSuccessful(":hotRunJvm") | ||
check.logContains("Compose Hot Reload ($externalHotReloadVersion)") | ||
check.logContains("Kotlin MPP app is running!") | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat | ||
|
||
plugins { | ||
id "com.android.application" | ||
id "org.jetbrains.kotlin.multiplatform" | ||
id "org.jetbrains.kotlin.plugin.compose" | ||
id "org.jetbrains.compose" | ||
} | ||
|
||
kotlin { | ||
// empty stub (no actual android app) to detect configuration conflicts | ||
// like https://github.com/JetBrains/compose-jb/issues/2345 | ||
androidTarget() | ||
|
||
jvm() | ||
sourceSets { | ||
jvmMain { | ||
dependsOn(commonMain) | ||
|
||
dependencies { | ||
implementation(compose.desktop.currentOs) | ||
} | ||
} | ||
} | ||
jvmToolchain { | ||
languageVersion.set(JavaLanguageVersion.of(11)) | ||
} | ||
} | ||
|
||
android { | ||
namespace = "org.jetbrains.compose.testapp" | ||
compileSdk = 35 | ||
|
||
defaultConfig { | ||
minSdk = 23 | ||
targetSdk = 35 | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "MainKt" | ||
nativeDistributions { | ||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) | ||
|
||
packageVersion = "1.0.0" | ||
packageName = "TestPackage" | ||
description = "Test description" | ||
copyright = "Test Copyright Holder" | ||
vendor = "Test Vendor" | ||
|
||
linux { | ||
shortcut = true | ||
packageName = "test-package" | ||
debMaintainer = "example@example.com" | ||
menuGroup = "menu-group" | ||
} | ||
windows { | ||
console = true | ||
dirChooser = true | ||
perUserInstall = true | ||
shortcut = true | ||
menu = true | ||
menuGroup = "compose" | ||
upgradeUuid = "2d6ff464-75be-40ad-a256-56420b9cc374" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
android.useAndroidX=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
pluginManagement { | ||
plugins { | ||
id 'org.jetbrains.kotlin.multiplatform' version 'KOTLIN_VERSION_PLACEHOLDER' | ||
id 'org.jetbrains.kotlin.plugin.compose' version 'KOTLIN_VERSION_PLACEHOLDER' | ||
id 'org.jetbrains.compose' version 'COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER' | ||
id 'com.android.application' version 'AGP_VERSION_PLACEHOLDER' | ||
} | ||
repositories { | ||
mavenLocal() | ||
gradlePluginPortal() | ||
mavenCentral() | ||
google() | ||
maven { | ||
url 'https://maven.pkg.jetbrains.space/public/p/compose/dev' | ||
} | ||
maven { | ||
url 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/' | ||
} | ||
} | ||
} | ||
dependencyResolutionManagement { | ||
repositories { | ||
mavenCentral() | ||
google() | ||
maven { | ||
url 'https://maven.pkg.jetbrains.space/public/p/compose/dev' | ||
} | ||
maven { | ||
url 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/' | ||
} | ||
mavenLocal() | ||
} | ||
} | ||
rootProject.name = "mpp" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import java.io.File | ||
|
||
fun message() = "Kotlin MPP app is running!" | ||
|
||
fun main() { | ||
println(message()) | ||
File("started").createNewFile() | ||
//wait for reload | ||
while(!message().startsWith("KMP")){ | ||
Thread.sleep(200) | ||
} | ||
println(message()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ compose.tests.gradle-agp.exclude=8.7/8.9.0, 8.7/9.0.0-alpha01 | |
# A version of Gradle plugin, that will be published, | ||
# unless overridden by COMPOSE_GRADLE_PLUGIN_VERSION env var. | ||
deploy.version=9999.0.0-SNAPSHOT | ||
hotreload.version=1.0.0-beta08 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess Ii's supposed to be configured on CI, here is the place only for some placeholder cc @igordmn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to configure it only here, not on CI. Because it is a dependency version, not a version of the building component. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is usually better to define such versions in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it will require JDK 11 to be installed that won't be a case on CI soon.
I'd suggest approach like here - 51a87ca