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
This commit is contained in:
Nicola Corti
2023-05-31 15:22:21 -07:00
committed by Facebook GitHub Bot
parent 186f4d318d
commit 9a0ba05d13
9 changed files with 118 additions and 41 deletions

View File

@@ -7,6 +7,7 @@
plugins {
id("com.android.library")
id("publish")
}
android {

View File

@@ -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

View File

@@ -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()
}

View File

@@ -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<MavenPublication>("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<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach { dependsOn(signingTasks) }
val String.byProperty: String?
get() = providers.gradleProperty(this).orNull

View File

@@ -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 {

View File

@@ -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

View File

@@ -7,6 +7,7 @@
plugins {
id("com.android.library")
id("publish")
}
android {

View File

@@ -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

View File

@@ -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")