Browse Source

Add publishing infrastructure for MPP targets

pull/1658/head
Alexey Tsvetkov 4 years ago
parent
commit
d08c4d13cc
  1. 12
      compose/README.md
  2. 154
      compose/build.gradle.kts
  3. 12
      compose/buildSrc/build.gradle.kts
  4. 47
      compose/buildSrc/src/main/kotlin/AbstractComposePublishingTask.kt
  5. 9
      compose/buildSrc/src/main/kotlin/ComposeComponent.kt
  6. 66
      compose/buildSrc/src/main/kotlin/ComposePlatforms.kt
  7. 17
      compose/buildSrc/src/main/kotlin/ComposeProperties.kt
  8. 13
      compose/buildSrc/src/main/kotlin/utils.kt
  9. 2
      compose/gradle/wrapper/gradle-wrapper.properties
  10. 8
      compose/scripts/publishExtendedIconsToMavenLocal
  11. 12
      compose/scripts/publishGradlePluginToMavenLocal
  12. 8
      compose/scripts/publishToMavenLocal
  13. 13
      compose/scripts/publishWebComponentsToMavenLocal
  14. 4
      compose/settings.gradle.kts

12
compose/README.md

@ -63,3 +63,15 @@ Run tests for Web: @@ -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`.

154
compose/build.gradle.kts

@ -1,86 +1,106 @@ @@ -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))
val isOelPublication = project.findProperty("oel.publication") == "true"
val isWebExist = composeBuild.projectDir.resolve(".jbWebExistsMarker").exists()
fun Task.dependsOnComposeTask(name: String) {
dependsOn(project.composeBuild?.task(name) ?: return)
}
// To show all projects which use `xxx` task, run:
// ./gradlew -p frameworks/support help --task xxx
open class ComposePublishingTask : AbstractComposePublishingTask() {
override fun dependsOnComposeTask(task: String) {
dependsOn(project.composeBuild?.task(task) ?: return)
}
}
tasks.register("publishComposeJb") {
dependsOnComposeTask(":compose:compiler:compiler:publishMavenPublicationToMavenRepository")
dependsOnComposeTask(":compose:compiler:compiler-hosted:publishMavenPublicationToMavenRepository")
dependsOnComposeTask(":compose:ui:ui-tooling-data:publishMavenPublicationToMavenRepository")
val composeProperties = ComposeProperties(project)
val isWebExist =
project.composeBuild?.run { projectDir.resolve(".jbWebExistsMarker").exists() } ?: false
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")
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(
":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")
}
}
ComposeComponent(":compose:material:material-icons-extended", supportedPlatforms = ComposePlatforms.JVM_BASED),
)
if (isWebExist) {
listOf(
":compose:runtime:runtime",
).forEach {
dependsOnComposeTask("$it:publishJsPublicationToMavenRepository")
}
}
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("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")
if (!isOelPublication) {
dependsOnComposeTask("$it:publishAndroidDebugPublicationToMavenRepository")
dependsOnComposeTask("$it:publishAndroidReleasePublicationToMavenRepository")
}
}
tasks.register("publishComposeJbExtendedIcons", ComposePublishingTask::class) {
repository = "MavenRepository"
iconsPublications()
}
tasks.register("publishComposeJbExtendedIconsToMavenLocal", ComposePublishingTask::class) {
repository = "MavenLocal"
iconsPublications()
}
tasks.register("testComposeJbDesktop") {

12
compose/buildSrc/build.gradle.kts

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
compileOnly(gradleApi())
}

47
compose/buildSrc/src/main/kotlin/AbstractComposePublishingTask.kt

@ -0,0 +1,47 @@ @@ -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

@ -0,0 +1,9 @@ @@ -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

@ -0,0 +1,66 @@ @@ -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

@ -0,0 +1,17 @@ @@ -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

@ -0,0 +1,13 @@ @@ -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")

2
compose/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,5 +1,5 @@ @@ -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

@ -0,0 +1,8 @@ @@ -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

@ -0,0 +1,12 @@ @@ -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

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"
. ./prepare
pushd ..
./gradlew publishComposeJbToMavenLocal $COMPOSE_DEFAULT_GRADLE_ARGS "$@" || exit 1
popd

13
compose/scripts/publishWebComponentsToMavenLocal

@ -0,0 +1,13 @@ @@ -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

4
compose/settings.gradle.kts

@ -12,4 +12,6 @@ pluginManagement { @@ -12,4 +12,6 @@ pluginManagement {
}
}
includeBuild("frameworks/support")
if (System.getProperty("idea.active") != "true") {
includeBuild("frameworks/support")
}

Loading…
Cancel
Save