From eec0f9abe4c5984f6cd2a424b83e7edf63725f68 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Mon, 8 Nov 2021 12:10:26 +0300 Subject: [PATCH] Configure publishing to Maven Central (#1351) Fixes #1106 --- compose/build.gradle.kts | 72 +++++++++++++++++++ .../scripts/reuploadArtifactsToMavenCentral | 8 +++ compose/settings.gradle.kts | 13 ++++ 3 files changed, 93 insertions(+) create mode 100755 compose/scripts/reuploadArtifactsToMavenCentral diff --git a/compose/build.gradle.kts b/compose/build.gradle.kts index e93bcb6817..4901103bda 100644 --- a/compose/build.gradle.kts +++ b/compose/build.gradle.kts @@ -1,3 +1,9 @@ +import org.jetbrains.compose.internal.publishing.* + +plugins { + signing +} + val composeBuild = gradle.includedBuild("support") fun Task.dependsOnComposeTask(name: String) = dependsOn(composeBuild.task(name)) @@ -131,3 +137,69 @@ tasks.register("testComposeModules") { // used in https://github.com/JetBrains/a tasks.register("run") { dependsOnComposeTask(":compose:desktop:desktop:desktop-samples:run") } + +val mavenCentral = MavenCentralProperties(project) +if (mavenCentral.signArtifacts) { + signing.useInMemoryPgpKeys( + mavenCentral.signArtifactsKey.get(), + mavenCentral.signArtifactsPassword.get() + ) +} + +val publishingDir = project.layout.buildDirectory.dir("publishing") +val originalArtifactsRoot = publishingDir.map { it.dir("original") } +val preparedArtifactsRoot = publishingDir.map { it.dir("prepared") } +val modulesFile = publishingDir.map { it.file("modules.txt") } + +val findComposeModules by tasks.registering(FindModulesInSpaceTask::class) { + requestedGroupId.set("org.jetbrains.compose") + requestedVersion.set(mavenCentral.version) + spaceInstanceUrl.set("https://public.jetbrains.space") + spaceClientId.set(System.getenv("COMPOSE_REPO_USERNAME") ?: "") + spaceClientSecret.set(System.getenv("COMPOSE_REPO_KEY") ?: "") + spaceProjectId.set(System.getenv("COMPOSE_DEV_REPO_PROJECT_ID") ?: "") + spaceRepoId.set(System.getenv("COMPOSE_DEV_REPO_REPO_ID") ?: "") + modulesTxtFile.set(modulesFile) +} + +val downloadArtifactsFromComposeDev by tasks.registering(DownloadFromSpaceMavenRepoTask::class) { + dependsOn(findComposeModules) + modulesToDownload.set(project.provider { readComposeModules(modulesFile, originalArtifactsRoot) }) + spaceRepoUrl.set("https://maven.pkg.jetbrains.space/public/p/compose/dev") +} + +val fixModulesBeforePublishing by tasks.registering(FixModulesBeforePublishingTask::class) { + dependsOn(downloadArtifactsFromComposeDev) + inputRepoDir.set(originalArtifactsRoot) + outputRepoDir.set(preparedArtifactsRoot) +} + +val reuploadArtifactsToMavenCentral by tasks.registering(UploadToSonatypeTask::class) { + dependsOn(fixModulesBeforePublishing) + + version.set(mavenCentral.version) + modulesToUpload.set(project.provider { readComposeModules(modulesFile, preparedArtifactsRoot) }) + + sonatypeServer.set("https://oss.sonatype.org") + user.set(mavenCentral.user) + password.set(mavenCentral.password) + autoCommitOnSuccess.set(mavenCentral.autoCommitOnSuccess) + autoDropOnError.set(mavenCentral.autoDropOnError) + stagingProfileName.set("org.jetbrains.compose") +} + +fun readComposeModules( + modulesFile: Provider, + repoRoot: Provider +): List = + modulesFile.get().asFile.readLines() + .filter { it.isNotBlank() } + .map { line -> + val (group, artifact, version) = line.split(":") + ModuleToUpload( + groupId = group, + artifactId = artifact, + version = version, + localDir = repoRoot.get().asFile.resolve("$group/$artifact/$version") + ) + } \ No newline at end of file diff --git a/compose/scripts/reuploadArtifactsToMavenCentral b/compose/scripts/reuploadArtifactsToMavenCentral new file mode 100755 index 0000000000..0856aabfc8 --- /dev/null +++ b/compose/scripts/reuploadArtifactsToMavenCentral @@ -0,0 +1,8 @@ +#!/bin/bash + +cd "$(dirname "$0")" +. ./prepare + +pushd .. +./gradlew reuploadArtifactsToMavenCentral $COMPOSE_DEFAULT_GRADLE_ARGS "$@" || exit 1 +popd diff --git a/compose/settings.gradle.kts b/compose/settings.gradle.kts index 911b403205..747219d8ff 100644 --- a/compose/settings.gradle.kts +++ b/compose/settings.gradle.kts @@ -1 +1,14 @@ +pluginManagement { + buildscript { + repositories { + mavenCentral() + maven("https://maven.pkg.jetbrains.space/public/p/compose/internal") + maven("https://maven.pkg.jetbrains.space/public/p/space/maven") + } + dependencies { + classpath("org.jetbrains.compose.internal.build-helpers:publishing:0.0.2") + } + } +} + includeBuild("frameworks/support") \ No newline at end of file