mirror of
https://github.com/jlengrand/compose-multiplatform.git
synced 2026-03-10 08:11:20 +00:00
Add publishing infrastructure for MPP targets
This commit is contained in:
@@ -63,3 +63,15 @@ Run tests for Web:
|
||||
```
|
||||
./scripts/testWeb
|
||||
```
|
||||
|
||||
## Multiplatform build
|
||||
|
||||
```console
|
||||
./scripts/downloadAndroidSdk
|
||||
export COMPOSE_CUSTOM_VERSION=1.1.0-beta04
|
||||
./scripts/publishToMavenLocal -Pcompose.platforms=all
|
||||
./scripts/publishGradlePluginToMavenLocal
|
||||
./scripts/publishWebComponentsToMavenLocal
|
||||
```
|
||||
`-Pcompose.platforms=all` could be replace with comma-separated list of platforms, such as `js,jvm,androidDebug,androidRelease,macosx64,uikitx64`.
|
||||
|
||||
|
||||
@@ -1,86 +1,106 @@
|
||||
import org.gradle.api.*
|
||||
import org.jetbrains.compose.internal.publishing.*
|
||||
|
||||
plugins {
|
||||
signing
|
||||
}
|
||||
|
||||
val composeBuild = gradle.includedBuild("support")
|
||||
fun Task.dependsOnComposeTask(name: String) = dependsOn(composeBuild.task(name))
|
||||
fun Task.dependsOnComposeTask(name: String) {
|
||||
dependsOn(project.composeBuild?.task(name) ?: return)
|
||||
}
|
||||
|
||||
val isOelPublication = project.findProperty("oel.publication") == "true"
|
||||
val isWebExist = composeBuild.projectDir.resolve(".jbWebExistsMarker").exists()
|
||||
open class ComposePublishingTask : AbstractComposePublishingTask() {
|
||||
override fun dependsOnComposeTask(task: String) {
|
||||
dependsOn(project.composeBuild?.task(task) ?: return)
|
||||
}
|
||||
}
|
||||
|
||||
val composeProperties = ComposeProperties(project)
|
||||
val isWebExist =
|
||||
project.composeBuild?.run { projectDir.resolve(".jbWebExistsMarker").exists() } ?: false
|
||||
|
||||
val mainComponents =
|
||||
listOf(
|
||||
ComposeComponent(":compose:animation:animation"),
|
||||
ComposeComponent(":compose:animation:animation-core"),
|
||||
ComposeComponent(":compose:animation:animation-graphics", supportedPlatforms = ComposePlatforms.JVM_BASED),
|
||||
ComposeComponent(":compose:foundation:foundation"),
|
||||
ComposeComponent(":compose:foundation:foundation-layout"),
|
||||
ComposeComponent(":compose:material:material"),
|
||||
ComposeComponent(":compose:material3:material3", supportedPlatforms = ComposePlatforms.JVM_BASED),
|
||||
ComposeComponent(":compose:material:material-icons-core"),
|
||||
ComposeComponent(":compose:material:material-ripple"),
|
||||
ComposeComponent(":compose:runtime:runtime"),
|
||||
ComposeComponent(":compose:runtime:runtime-saveable"),
|
||||
ComposeComponent(":compose:ui:ui"),
|
||||
ComposeComponent(":compose:ui:ui-geometry"),
|
||||
ComposeComponent(":compose:ui:ui-graphics"),
|
||||
ComposeComponent(":compose:ui:ui-test", supportedPlatforms = ComposePlatforms.JVM_BASED),
|
||||
ComposeComponent(":compose:ui:ui-test-junit4", supportedPlatforms = ComposePlatforms.JVM_BASED),
|
||||
ComposeComponent(":compose:ui:ui-text"),
|
||||
ComposeComponent(":compose:ui:ui-tooling", supportedPlatforms = ComposePlatforms.JVM_BASED),
|
||||
ComposeComponent(":compose:ui:ui-tooling-preview", supportedPlatforms = ComposePlatforms.JVM_BASED),
|
||||
ComposeComponent(":compose:ui:ui-unit"),
|
||||
ComposeComponent(":compose:ui:ui-util", supportedPlatforms = ComposePlatforms.ALL),
|
||||
)
|
||||
|
||||
val iconsComponents =
|
||||
listOf(
|
||||
ComposeComponent(":compose:material:material-icons-extended", supportedPlatforms = ComposePlatforms.JVM_BASED),
|
||||
)
|
||||
|
||||
fun ComposePublishingTask.mainPublications() {
|
||||
publish(":compose:compiler:compiler", publications = listOf("Maven"))
|
||||
publish(":compose:compiler:compiler-hosted", publications = listOf("Maven"))
|
||||
publish(
|
||||
":compose:ui:ui-tooling-data",
|
||||
onlyWithPlatforms = setOf(ComposePlatforms.AndroidRelease, ComposePlatforms.AndroidDebug),
|
||||
publications = listOf("Maven")
|
||||
)
|
||||
|
||||
publish(
|
||||
":compose:desktop:desktop",
|
||||
onlyWithPlatforms = setOf(ComposePlatforms.Desktop),
|
||||
publications = listOf(
|
||||
"KotlinMultiplatform",
|
||||
"Jvm",
|
||||
"Jvmlinux-x64",
|
||||
"Jvmlinux-arm64",
|
||||
"Jvmmacos-x64",
|
||||
"Jvmmacos-arm64",
|
||||
"Jvmwindows-x64"
|
||||
)
|
||||
)
|
||||
|
||||
mainComponents.forEach { publishMultiplatform(it) }
|
||||
}
|
||||
|
||||
fun ComposePublishingTask.iconsPublications() {
|
||||
iconsComponents.forEach { publishMultiplatform(it) }
|
||||
}
|
||||
|
||||
// To show all projects which use `xxx` task, run:
|
||||
// ./gradlew -p frameworks/support help --task xxx
|
||||
tasks.register("publishComposeJb", ComposePublishingTask::class) {
|
||||
repository = "MavenRepository"
|
||||
mainPublications()
|
||||
}
|
||||
|
||||
tasks.register("publishComposeJb") {
|
||||
dependsOnComposeTask(":compose:compiler:compiler:publishMavenPublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:compiler:compiler-hosted:publishMavenPublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:ui:ui-tooling-data:publishMavenPublicationToMavenRepository")
|
||||
|
||||
dependsOnComposeTask(":compose:desktop:desktop:publishKotlinMultiplatformPublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:desktop:desktop:publishJvmPublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:desktop:desktop:publishJvmlinux-x64PublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:desktop:desktop:publishJvmlinux-arm64PublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:desktop:desktop:publishJvmmacos-x64PublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:desktop:desktop:publishJvmmacos-arm64PublicationToMavenRepository")
|
||||
dependsOnComposeTask(":compose:desktop:desktop:publishJvmwindows-x64PublicationToMavenRepository")
|
||||
|
||||
listOf(
|
||||
":compose:animation:animation",
|
||||
":compose:animation:animation-core",
|
||||
":compose:animation:animation-graphics",
|
||||
":compose:foundation:foundation",
|
||||
":compose:foundation:foundation-layout",
|
||||
":compose:material:material",
|
||||
":compose:material3:material3",
|
||||
":compose:material:material-icons-core",
|
||||
":compose:material:material-ripple",
|
||||
":compose:runtime:runtime",
|
||||
":compose:runtime:runtime-saveable",
|
||||
":compose:ui:ui",
|
||||
":compose:ui:ui-geometry",
|
||||
":compose:ui:ui-graphics",
|
||||
":compose:ui:ui-test",
|
||||
":compose:ui:ui-test-junit4",
|
||||
":compose:ui:ui-text",
|
||||
":compose:ui:ui-tooling",
|
||||
":compose:ui:ui-tooling-preview",
|
||||
":compose:ui:ui-unit",
|
||||
":compose:ui:ui-util",
|
||||
).forEach {
|
||||
dependsOnComposeTask("$it:publishKotlinMultiplatformPublicationToMavenRepository")
|
||||
dependsOnComposeTask("$it:publishDesktopPublicationToMavenRepository")
|
||||
|
||||
if (!isOelPublication) {
|
||||
dependsOnComposeTask("$it:publishAndroidDebugPublicationToMavenRepository")
|
||||
dependsOnComposeTask("$it:publishAndroidReleasePublicationToMavenRepository")
|
||||
}
|
||||
}
|
||||
|
||||
if (isWebExist) {
|
||||
listOf(
|
||||
":compose:runtime:runtime",
|
||||
).forEach {
|
||||
dependsOnComposeTask("$it:publishJsPublicationToMavenRepository")
|
||||
}
|
||||
}
|
||||
tasks.register("publishComposeJbToMavenLocal", ComposePublishingTask::class) {
|
||||
repository = "MavenLocal"
|
||||
mainPublications()
|
||||
}
|
||||
|
||||
// separate task that cannot be built in parallel (because it requires too much RAM).
|
||||
// should be run with "--max-workers=1"
|
||||
tasks.register("publishComposeJbExtendedIcons") {
|
||||
listOf(
|
||||
":compose:material:material-icons-extended",
|
||||
).forEach {
|
||||
dependsOnComposeTask("$it:publishKotlinMultiplatformPublicationToMavenRepository")
|
||||
dependsOnComposeTask("$it:publishDesktopPublicationToMavenRepository")
|
||||
tasks.register("publishComposeJbExtendedIcons", ComposePublishingTask::class) {
|
||||
repository = "MavenRepository"
|
||||
iconsPublications()
|
||||
}
|
||||
|
||||
if (!isOelPublication) {
|
||||
dependsOnComposeTask("$it:publishAndroidDebugPublicationToMavenRepository")
|
||||
dependsOnComposeTask("$it:publishAndroidReleasePublicationToMavenRepository")
|
||||
}
|
||||
}
|
||||
tasks.register("publishComposeJbExtendedIconsToMavenLocal", ComposePublishingTask::class) {
|
||||
repository = "MavenLocal"
|
||||
iconsPublications()
|
||||
}
|
||||
|
||||
tasks.register("testComposeJbDesktop") {
|
||||
|
||||
12
compose/buildSrc/build.gradle.kts
Normal file
12
compose/buildSrc/build.gradle.kts
Normal file
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(gradleApi())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
|
||||
*/
|
||||
import org.gradle.api.*
|
||||
import org.gradle.api.tasks.Internal
|
||||
|
||||
abstract class AbstractComposePublishingTask : DefaultTask() {
|
||||
@get:Internal
|
||||
lateinit var repository: String
|
||||
|
||||
private val composeProperties by lazy {
|
||||
ComposeProperties(project)
|
||||
}
|
||||
private val isOelPublication: Boolean by lazy {
|
||||
composeProperties.isOelPublication
|
||||
}
|
||||
private val targetPlatforms: Set<ComposePlatforms> by lazy {
|
||||
composeProperties.targetPlatforms
|
||||
}
|
||||
|
||||
abstract fun dependsOnComposeTask(task: String)
|
||||
|
||||
fun publish(project: String, publications: Collection<String>) {
|
||||
for (publication in publications) {
|
||||
dependsOnComposeTask("$project:publish${publication}PublicationTo$repository")
|
||||
}
|
||||
}
|
||||
|
||||
fun publish(project: String, publications: Collection<String>, onlyWithPlatforms: Set<ComposePlatforms>) {
|
||||
if (onlyWithPlatforms.any { it in targetPlatforms }) {
|
||||
publish(project, publications)
|
||||
}
|
||||
}
|
||||
|
||||
fun publishMultiplatform(component: ComposeComponent) {
|
||||
dependsOnComposeTask("${component.path}:publish${ComposePlatforms.KotlinMultiplatform.name}PublicationTo$repository")
|
||||
|
||||
for (platform in targetPlatforms) {
|
||||
if (platform !in component.supportedPlatforms) continue
|
||||
|
||||
if (platform in ComposePlatforms.ANDROID && isOelPublication) continue
|
||||
|
||||
dependsOnComposeTask("${component.path}:publish${platform.name}PublicationTo$repository")
|
||||
}
|
||||
}
|
||||
}
|
||||
9
compose/buildSrc/src/main/kotlin/ComposeComponent.kt
Normal file
9
compose/buildSrc/src/main/kotlin/ComposeComponent.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
|
||||
*/
|
||||
|
||||
data class ComposeComponent(
|
||||
val path: String,
|
||||
val supportedPlatforms: Set<ComposePlatforms> = ComposePlatforms.ALL
|
||||
)
|
||||
66
compose/buildSrc/src/main/kotlin/ComposePlatforms.kt
Normal file
66
compose/buildSrc/src/main/kotlin/ComposePlatforms.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import java.util.*
|
||||
|
||||
enum class ComposePlatforms(vararg val alternativeNames: String) {
|
||||
KotlinMultiplatform("Common"),
|
||||
Desktop("Jvm"),
|
||||
AndroidDebug("Android"),
|
||||
AndroidRelease("Android"),
|
||||
Js("Web"),
|
||||
MacosX64("Macos"),
|
||||
MacosArm64("Macos"),
|
||||
UikitX64("UiKit"),
|
||||
UikitArm64("UiKit");
|
||||
|
||||
fun matches(nameCandidate: String): Boolean =
|
||||
listOf(name, *alternativeNames).any { it.equals(nameCandidate, ignoreCase = true) }
|
||||
|
||||
companion object {
|
||||
val ALL = EnumSet.allOf(ComposePlatforms::class.java)
|
||||
|
||||
val JVM_BASED = EnumSet.of(
|
||||
ComposePlatforms.Desktop,
|
||||
ComposePlatforms.AndroidDebug,
|
||||
ComposePlatforms.AndroidRelease
|
||||
)
|
||||
|
||||
val ANDROID = EnumSet.of(
|
||||
ComposePlatforms.AndroidDebug,
|
||||
ComposePlatforms.AndroidRelease
|
||||
)
|
||||
|
||||
/**
|
||||
* Maps comma separated list of platforms into a set of [ComposePlatforms]
|
||||
* The function is case- and whitespace-insensetive.
|
||||
*
|
||||
* Special value: all
|
||||
*/
|
||||
fun parse(platformsNames: String): Set<ComposePlatforms> {
|
||||
val platforms = EnumSet.noneOf(ComposePlatforms::class.java)
|
||||
val unknownNames = arrayListOf<String>()
|
||||
|
||||
for (name in platformsNames.split(",").map { it.trim() }) {
|
||||
if (name.equals("all", ignoreCase = true)) {
|
||||
return ALL
|
||||
}
|
||||
|
||||
val publication = ALL.firstOrNull { it.matches(name) }
|
||||
if (publication != null) {
|
||||
platforms.add(publication)
|
||||
} else {
|
||||
unknownNames.add(name)
|
||||
}
|
||||
}
|
||||
|
||||
if (unknownNames.isNotEmpty()) {
|
||||
error("Unknown platforms: ${unknownNames.joinToString(", ")}")
|
||||
}
|
||||
|
||||
return platforms
|
||||
}
|
||||
}
|
||||
}
|
||||
17
compose/buildSrc/src/main/kotlin/ComposeProperties.kt
Normal file
17
compose/buildSrc/src/main/kotlin/ComposeProperties.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import org.gradle.api.*
|
||||
|
||||
class ComposeProperties(private val myProject: Project) {
|
||||
val isOelPublication: Boolean
|
||||
get() = myProject.findProperty("oel.publication") == "true"
|
||||
|
||||
val targetPlatforms: Set<ComposePlatforms>
|
||||
get() {
|
||||
val requestedPlatforms = myProject.findProperty("compose.platforms")?.toString() ?: "jvm, android"
|
||||
return ComposePlatforms.parse(requestedPlatforms)
|
||||
}
|
||||
}
|
||||
13
compose/buildSrc/src/main/kotlin/utils.kt
Normal file
13
compose/buildSrc/src/main/kotlin/utils.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.initialization.IncludedBuild
|
||||
|
||||
val isInIdea: Boolean
|
||||
get() = System.getProperty("idea.active") == "true"
|
||||
|
||||
val Project.composeBuild: IncludedBuild?
|
||||
get() = if (isInIdea) null else gradle.includedBuild("support")
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
8
compose/scripts/publishExtendedIconsToMavenLocal
Executable file
8
compose/scripts/publishExtendedIconsToMavenLocal
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
. ./prepare
|
||||
|
||||
pushd ..
|
||||
./gradlew publishComposeJbExtendedIconsToMavenLocal $COMPOSE_DEFAULT_GRADLE_ARGS --max-workers=1 "$@" || exit 1
|
||||
popd
|
||||
12
compose/scripts/publishGradlePluginToMavenLocal
Executable file
12
compose/scripts/publishGradlePluginToMavenLocal
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
if [[ -z "$COMPOSE_CUSTOM_VERSION" ]]; then
|
||||
echo "Must provide COMPOSE_CUSTOM_VERSION in environment" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pushd ../../gradle-plugins
|
||||
./gradlew publishToMavenLocal -Pcompose.version="$COMPOSE_CUSTOM_VERSION" -Pdeploy.version="$COMPOSE_CUSTOM_VERSION" -Pcompose.with.web=true || exit 1
|
||||
popd
|
||||
8
compose/scripts/publishToMavenLocal
Executable file
8
compose/scripts/publishToMavenLocal
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
. ./prepare
|
||||
|
||||
pushd ..
|
||||
./gradlew publishComposeJbToMavenLocal $COMPOSE_DEFAULT_GRADLE_ARGS "$@" || exit 1
|
||||
popd
|
||||
13
compose/scripts/publishWebComponentsToMavenLocal
Executable file
13
compose/scripts/publishWebComponentsToMavenLocal
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
if [[ -z "$COMPOSE_CUSTOM_VERSION" ]]; then
|
||||
echo "Must provide COMPOSE_CUSTOM_VERSION in environment" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pushd ../../web
|
||||
./gradlew publishToMavenLocal -PCOMPOSE_CORE_VERSION="$COMPOSE_CUSTOM_VERSION" -PCOMPOSE_WEB_VERSION="$COMPOSE_CUSTOM_VERSION" || exit 1
|
||||
popd
|
||||
|
||||
@@ -12,4 +12,6 @@ pluginManagement {
|
||||
}
|
||||
}
|
||||
|
||||
includeBuild("frameworks/support")
|
||||
if (System.getProperty("idea.active") != "true") {
|
||||
includeBuild("frameworks/support")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user