Skip to content

Commit 966b8e5

Browse files
committed
Update gradle plugin: Deprecate experimental configuration for Compose for Web (#4796)
Since 1.6.10 Compose for Web goes to Alpha and experimental configuration is not needed anymore. We'll configure the web targets by default when they're added to projects. ## Testing - I built the plugin to mavenLocal. And used it in a couple of our samples. - After gradle sync completes, I observe the Deprecation warning in build.gradle.kts on `compose.experimental.web` usages (see a screenshot below) <img width="1022" alt="Screenshot 2024-05-10 at 15 41 14" src="https://github.com/JetBrains/compose-multiplatform/assets/7372778/e8ede073-8d34-4dd7-ae74-c83ca0ff5c96"> Then I remove deprecated API usages and test that the project works without it: - run `./gradlew clean` just in case - run the app: `./gradlew wasmJsBrowserRun` and `./gradlew jsBrowserRun` - both run fine - build the production distribution: `./gradlew wasmJsBrowserDistribution` - `cd ..../build/dist/wasmJs/productionExecutable` and run `python -m http.server`, open a browser at `http://localhost:8000` - the app should work the same way it works with gradle tasks above <!-- Optional --> This should be tested by QA ## Release Notes ### Highlights - Web - Compose for Web goes to Alpha! Some experimental Compose Multiplatform Gradle plugin APIs for web app configuration were deprecated. Their usage is not required anymore. (cherry picked from commit 885ea3d)
1 parent ab63e4d commit 966b8e5

File tree

10 files changed

+104
-75
lines changed

10 files changed

+104
-75
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.jetbrains.compose.internal.utils.currentTarget
2727
import org.jetbrains.compose.resources.ResourcesExtension
2828
import org.jetbrains.compose.resources.configureComposeResources
2929
import org.jetbrains.compose.web.WebExtension
30+
import org.jetbrains.compose.web.internal.configureWeb
3031
import org.jetbrains.kotlin.com.github.gundy.semver4j.SemVer
3132
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
3233
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
@@ -65,7 +66,7 @@ abstract class ComposePlugin : Plugin<Project> {
6566

6667
project.afterEvaluate {
6768
configureDesktop(project, desktopExtension)
68-
project.configureExperimental(composeExtension, experimentalExtension)
69+
project.configureWeb(composeExtension)
6970
project.plugins.withId(KOTLIN_MPP_PLUGIN_ID) {
7071
val mppExt = project.mppExt
7172
project.configureExperimentalTargetsFlagsCheck(mppExt)

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalExtension.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ import javax.inject.Inject
1212
abstract class ExperimentalExtension @Inject constructor(
1313
objects: ObjectFactory
1414
) {
15+
16+
@Deprecated(
17+
message = "Starting from 1.6.10, Compose for Web goes to Alpha. Experimental configuration is not needed anymore.",
18+
)
1519
val web: ExperimentalWebExtension = objects.newInstance(ExperimentalWebExtension::class.java)
20+
21+
@Deprecated(
22+
message = "Starting from 1.6.10, Compose for Web goes to Alpha. Experimental configuration is not needed anymore."
23+
)
1624
fun web(action: Action<ExperimentalWebExtension>) {
1725
action.execute(web)
1826
}

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebApplication.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ package org.jetbrains.compose.experimental.dsl
77

88
import javax.inject.Inject
99

10+
@Deprecated(
11+
message = "Starting from 1.6.10, Compose for Web goes to Alpha. Experimental configuration is not needed anymore.",
12+
)
1013
abstract class ExperimentalWebApplication @Inject constructor(
1114
@Suppress("unused")
1215
val name: String,

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/dsl/ExperimentalWebExtension.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ import org.gradle.api.model.ObjectFactory
1010
import org.gradle.api.plugins.ExtensionAware
1111
import javax.inject.Inject
1212

13+
@Deprecated(
14+
message = "Starting from 1.6.10, Compose for Web goes to Alpha. Experimental configuration is not needed anymore.",
15+
)
1316
abstract class ExperimentalWebExtension @Inject constructor(private val objectFactory: ObjectFactory) : ExtensionAware {
1417
internal var _isApplicationInitialized = false
1518
private set
1619

20+
@Deprecated(
21+
message = "Starting from 1.6.10, Compose for Web goes to Alpha. Experimental configuration is not needed anymore.",
22+
)
1723
val application: ExperimentalWebApplication by lazy {
1824
_isApplicationInitialized = true
1925
objectFactory.newInstance(ExperimentalWebApplication::class.java, "main")
2026
}
2127

28+
@Deprecated(
29+
message = "Starting from 1.6.10, Compose for Web goes to Alpha. Experimental configuration is not needed anymore.",
30+
)
2231
fun application(fn: Action<ExperimentalWebApplication>) {
2332
fn.execute(application)
2433
}

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/checkExperimentalTargets.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ private val TargetType.gradlePropertyName get() = "org.jetbrains.compose.experim
2727
private val EXPERIMENTAL_TARGETS: Set<TargetType> = setOf(
2828
TargetType("macos", presets = listOf("macosX64", "macosArm64")),
2929
TargetType("jscanvas", presets = listOf("jsIr", "js")),
30-
TargetType("wasm", presets = listOf("wasm", "wasmJs")),
3130
)
3231

3332
private sealed interface CheckResult {

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureExperimental.kt

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

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/web/tasks/ExperimentalUnpackSkikoWasmRuntimeTask.kt

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,10 @@
55

66
package org.jetbrains.compose.experimental.web.tasks
77

8-
import org.gradle.api.DefaultTask
9-
import org.gradle.api.file.ArchiveOperations
10-
import org.gradle.api.file.DirectoryProperty
11-
import org.gradle.api.file.FileCollection
12-
import org.gradle.api.file.FileSystemOperations
13-
import org.gradle.api.tasks.InputFiles
14-
import org.gradle.api.tasks.OutputDirectory
15-
import org.gradle.api.tasks.TaskAction
16-
import org.jetbrains.compose.internal.utils.clearDirs
17-
import java.io.File
18-
import javax.inject.Inject
8+
import org.jetbrains.compose.web.tasks.UnpackSkikoWasmRuntimeTask
199

20-
abstract class ExperimentalUnpackSkikoWasmRuntimeTask : DefaultTask() {
21-
@get:InputFiles
22-
lateinit var skikoRuntimeFiles: FileCollection
23-
24-
@get:OutputDirectory
25-
abstract val outputDir: DirectoryProperty
26-
27-
@get:Inject
28-
internal abstract val archiveOperations: ArchiveOperations
29-
30-
@get:Inject
31-
internal abstract val fileOperations: FileSystemOperations
32-
33-
@TaskAction
34-
fun run() {
35-
fileOperations.clearDirs(outputDir)
36-
37-
for (file in skikoRuntimeFiles.files) {
38-
if (file.name.endsWith(".jar", ignoreCase = true)) {
39-
unpackJar(file)
40-
}
41-
}
42-
}
43-
44-
private fun unpackJar(file: File) {
45-
fileOperations.copy { copySpec ->
46-
copySpec.from(archiveOperations.zipTree(file))
47-
copySpec.into(outputDir)
48-
}
49-
}
50-
}
10+
@Deprecated(
11+
message = "Starting from 1.6.10 Compose for Web goes to Alpha",
12+
replaceWith = ReplaceWith("UnpackSkikoWasmRuntimeTask")
13+
)
14+
abstract class ExperimentalUnpackSkikoWasmRuntimeTask : UnpackSkikoWasmRuntimeTask()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.jetbrains.compose.web.dsl
2+
3+
import javax.inject.Inject
4+
5+
abstract class WebApplication @Inject constructor(
6+
@Suppress("unused")
7+
val name: String,
8+
) {
9+
10+
}
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,33 @@
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
44
*/
55

6-
package org.jetbrains.compose.experimental.web.internal
6+
package org.jetbrains.compose.web.internal
77

88
import org.gradle.api.Project
99
import org.gradle.api.artifacts.Configuration
1010
import org.gradle.api.artifacts.ResolvedDependency
1111
import org.gradle.api.artifacts.UnresolvedDependency
1212
import org.gradle.api.provider.Provider
1313
import org.jetbrains.compose.ComposeBuildConfig
14-
import org.jetbrains.compose.experimental.dsl.ExperimentalWebApplication
15-
import org.jetbrains.compose.experimental.web.tasks.ExperimentalUnpackSkikoWasmRuntimeTask
14+
import org.jetbrains.compose.ComposeExtension
15+
import org.jetbrains.compose.web.tasks.UnpackSkikoWasmRuntimeTask
1616
import org.jetbrains.compose.internal.utils.*
1717
import org.jetbrains.compose.internal.utils.registerTask
1818
import org.jetbrains.compose.internal.utils.uppercaseFirstChar
19+
import org.jetbrains.compose.web.WebExtension
1920
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
2021

21-
internal fun Collection<KotlinJsIrTarget>.configureExperimentalWebApplication(
22-
project: Project,
23-
app: ExperimentalWebApplication
22+
internal fun Project.configureWeb(
23+
composeExt: ComposeExtension,
24+
) {
25+
val webExt = composeExt.extensions.getByType(WebExtension::class.java)
26+
// configure only if there is k/wasm or k/js target:
27+
webExt.targetsToConfigure(project)
28+
.configureWebApplication(project)
29+
}
30+
31+
internal fun Collection<KotlinJsIrTarget>.configureWebApplication(
32+
project: Project
2433
) {
2534
val skikoJsWasmRuntimeConfiguration = project.configurations.create("COMPOSE_SKIKO_JS_WASM_RUNTIME")
2635
val skikoJsWasmRuntimeDependency = skikoVersionProvider(project).map { skikoVersion ->
@@ -37,7 +46,7 @@ internal fun Collection<KotlinJsIrTarget>.configureExperimentalWebApplication(
3746
mainCompilation.defaultSourceSet.resources.srcDir(unpackedRuntimeDir)
3847
testCompilation.defaultSourceSet.resources.srcDir(unpackedRuntimeDir)
3948

40-
val unpackRuntime = project.registerTask<ExperimentalUnpackSkikoWasmRuntimeTask>(taskName) {
49+
val unpackRuntime = project.registerTask<UnpackSkikoWasmRuntimeTask>(taskName) {
4150
skikoRuntimeFiles = skikoJsWasmRuntimeConfiguration
4251
outputDir.set(unpackedRuntimeDir)
4352
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2020-2022 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.web.tasks
7+
8+
import org.gradle.api.DefaultTask
9+
import org.gradle.api.file.ArchiveOperations
10+
import org.gradle.api.file.DirectoryProperty
11+
import org.gradle.api.file.FileCollection
12+
import org.gradle.api.file.FileSystemOperations
13+
import org.gradle.api.tasks.InputFiles
14+
import org.gradle.api.tasks.OutputDirectory
15+
import org.gradle.api.tasks.TaskAction
16+
import org.jetbrains.compose.internal.utils.clearDirs
17+
import java.io.File
18+
import javax.inject.Inject
19+
20+
abstract class UnpackSkikoWasmRuntimeTask : DefaultTask() {
21+
@get:InputFiles
22+
lateinit var skikoRuntimeFiles: FileCollection
23+
24+
@get:OutputDirectory
25+
abstract val outputDir: DirectoryProperty
26+
27+
@get:Inject
28+
internal abstract val archiveOperations: ArchiveOperations
29+
30+
@get:Inject
31+
internal abstract val fileOperations: FileSystemOperations
32+
33+
@TaskAction
34+
fun run() {
35+
fileOperations.clearDirs(outputDir)
36+
37+
for (file in skikoRuntimeFiles.files) {
38+
if (file.name.endsWith(".jar", ignoreCase = true)) {
39+
unpackJar(file)
40+
}
41+
}
42+
}
43+
44+
private fun unpackJar(file: File) {
45+
fileOperations.copy { copySpec ->
46+
copySpec.from(archiveOperations.zipTree(file))
47+
copySpec.into(outputDir)
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)