From 9a0ba05d13b5bbc4daf5e76d7427058960f1bd3b Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Wed, 31 May 2023 15:22:21 -0700 Subject: [PATCH] Setup publishing of snapshots using `io.github.gradle-nexus.publish-plugin` Summary: This sets up publishing of -SNAPSHOT verison of Yoga using the Gradle plugin `io.github.gradle-nexus.publish-plugin` This plugin will take care of setting up the credentials for Sonatype and hitting the Maven repository. I've cleaned up the setup and centralized it inside a script plugin in the `build-logic` folder so we can easily add more module and just use `id("publish")` to publish them as well. Reviewed By: mdvacca Differential Revision: D46330013 fbshipit-source-id: 7221b296b9955a257fc290a2d1ac1d9fedfb787d --- android/build.gradle | 1 + android/gradle.properties | 12 --- build-logic/build.gradle.kts | 13 ++++ .../src/main/kotlin/publish.gradle.kts | 75 +++++++++++++++++++ build.gradle | 29 ++++++- gradle.properties | 14 +--- java/build.gradle | 1 + java/gradle.properties | 12 --- settings.gradle.kts | 2 + 9 files changed, 118 insertions(+), 41 deletions(-) delete mode 100644 android/gradle.properties create mode 100644 build-logic/build.gradle.kts create mode 100644 build-logic/src/main/kotlin/publish.gradle.kts delete mode 100644 java/gradle.properties diff --git a/android/build.gradle b/android/build.gradle index 3f2f501428..c142282e5e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,6 +7,7 @@ plugins { id("com.android.library") + id("publish") } android { diff --git a/android/gradle.properties b/android/gradle.properties deleted file mode 100644 index 76b74e27a3..0000000000 --- a/android/gradle.properties +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the LICENSE -# file in the root directory of this source tree. -# - -GROUP=com.facebook.yoga.android -POM_NAME=YogaLayout -POM_DESCRIPTION=YogaLayout -POM_ARTIFACT_ID=yoga-layout -POM_PACKAGING=aar diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 0000000000..451a20b6fa --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,13 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +plugins { `kotlin-dsl` } + +repositories { + mavenCentral() + gradlePluginPortal() +} diff --git a/build-logic/src/main/kotlin/publish.gradle.kts b/build-logic/src/main/kotlin/publish.gradle.kts new file mode 100644 index 0000000000..01cd9de366 --- /dev/null +++ b/build-logic/src/main/kotlin/publish.gradle.kts @@ -0,0 +1,75 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +plugins { + id("maven-publish") + id("signing") +} + +group = "com.facebook.yoga" + +if ("USE_SNAPSHOT".byProperty.toBoolean()) { + version = "${"VERSION_NAME".byProperty}-SNAPSHOT" +} else { + version = "VERSION_NAME".byProperty.toString() +} + +publishing { + publications { + register("default") { + groupId = project.group.toString() + artifactId = project.name + version = project.version.toString() + afterEvaluate { from(components["default"]) } + pom { + description.set("A cross-platform layout engine which implements Flexbox.") + name.set(project.name) + url.set("https://github.com/facebook/yoga.git") + licenses { + license { + name.set("MIT License") + url.set("https://github.com/facebook/yoga/blob/main/LICENSE") + distribution.set("repo") + } + } + developers { + developer { + id.set("Meta Open Source") + name.set("Meta Open Source") + email.set("opensource@meta.com") + } + } + scm { url.set("scm:git:git@github.com:facebook/yoga.git") } + } + } + } +} + +val signingKey = "SIGNING_KEY".byProperty +val signingPwd = "SIGNING_PWD".byProperty + +if (signingKey.isNullOrBlank() || signingPwd.isNullOrBlank()) { + logger.info("Signing disabled as the GPG key was not found") +} else { + logger.info("GPG Key found - Signing enabled") +} + +signing { + useInMemoryPgpKeys(signingKey, signingPwd) + sign(publishing.publications) + isRequired = !(signingKey.isNullOrBlank() || signingPwd.isNullOrBlank()) +} + +// Fix for https://youtrack.jetbrains.com/issue/KT-46466/ +// On Gradle 8+, the signing task is not correctly wired to the publishing tasks. +// This requires a fix on KGP that is currently pending. +val signingTasks = tasks.withType() + +tasks.withType().configureEach { dependsOn(signingTasks) } + +val String.byProperty: String? + get() = providers.gradleProperty(this).orNull diff --git a/build.gradle b/build.gradle index 32d03247cc..29fb537fa0 100644 --- a/build.gradle +++ b/build.gradle @@ -8,13 +8,34 @@ plugins { id("com.android.library") version "8.0.1" apply false id("com.android.application") version "8.0.1" apply false + id("io.github.gradle-nexus.publish-plugin") version "1.3.0" } allprojects { - repositories { - google() - mavenCentral() - } + repositories { + google() + mavenCentral() + } +} + +group = "com.facebook.yoga" + +if (project.hasProperty("USE_SNAPSHOT") && project.property("USE_SNAPSHOT").toBoolean()) { + version = getProperty("VERSION_NAME") + "-SNAPSHOT" +} else { + version = getProperty("VERSION_NAME") +} + +def sonatypeUsername = findProperty("SONATYPE_USERNAME")?.toString() +def sonatypePassword = findProperty("SONATYPE_PASSWORD")?.toString() + +nexusPublishing { + repositories { + sonatype { + username.set(sonatypeUsername) + password.set(sonatypePassword) + } + } } ext { diff --git a/gradle.properties b/gradle.properties index b79bac3111..bf5e62b7dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,16 +11,4 @@ android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M -VERSION_NAME=1.19.0 -POM_URL=https://github.com/facebook/yoga -POM_SCM_URL=https://github.com/facebook/yoga.git -POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git -POM_SCM_DEV_CONNECTION=scm:git:git@github.com:facebook/yoga.git -POM_LICENSE_NAME=MIT License -POM_LICENSE_URL=https://github.com/facebook/yoga/blob/main/LICENSE -POM_LICENSE_DIST=repo -POM_LICENCE_NAME=MIT License -POM_LICENCE_URL=https://github.com/facebook/yoga/blob/main/LICENSE -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=facebook -POM_DEVELOPER_NAME=facebook +VERSION_NAME=1.19.0 \ No newline at end of file diff --git a/java/build.gradle b/java/build.gradle index e7d59c5c24..f97b566adf 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -7,6 +7,7 @@ plugins { id("com.android.library") + id("publish") } android { diff --git a/java/gradle.properties b/java/gradle.properties deleted file mode 100644 index eb063444af..0000000000 --- a/java/gradle.properties +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the LICENSE -# file in the root directory of this source tree. -# - -GROUP=com.facebook.yoga -POM_NAME=Yoga -POM_DESCRIPTION=Java bindings to libyoga -POM_ARTIFACT_ID=yoga -POM_PACKAGING=aar diff --git a/settings.gradle.kts b/settings.gradle.kts index bc041b3f53..6200843845 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,6 +17,8 @@ plugins { id("com.gradle.enterprise").version("3.7.1") } include(":sample", ":yoga", ":yoga-layout") +includeBuild("build-logic") + project(":yoga").projectDir = file("java") project(":yoga-layout").projectDir = file("android")