Skip to content

Commit

Permalink
Setup publishing of snapshots using `io.github.gradle-nexus.publish-p…
Browse files Browse the repository at this point in the history
…lugin`

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
  • Loading branch information
cortinico authored and facebook-github-bot committed May 31, 2023
1 parent 186f4d3 commit 9a0ba05
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 41 deletions.
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

plugins {
id("com.android.library")
id("publish")
}

android {
Expand Down
12 changes: 0 additions & 12 deletions android/gradle.properties

This file was deleted.

13 changes: 13 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
}
75 changes: 75 additions & 0 deletions build-logic/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -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("[email protected]")
}
}
scm { url.set("scm:git:[email protected]: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
29 changes: 25 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 1 addition & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]: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
1 change: 1 addition & 0 deletions java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

plugins {
id("com.android.library")
id("publish")
}

android {
Expand Down
12 changes: 0 additions & 12 deletions java/gradle.properties

This file was deleted.

2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9a0ba05

Please sign in to comment.