Skip to content

Commit 0e2f090

Browse files
cortinicofacebook-github-bot
authored andcommitted
Setup publishing for Snapshot and Stable on Maven (#34967)
Summary: Pull Request resolved: #34967 This diff is a preparatory work for publishing artifacts on Maven Central. What it does is: 1. It sets up all the 3 modules (react-native, hermes-engine, external-artifacts) for publishg 2. Adds coordinates to publish on the Snapshot repository 3. Adds support for appendign -SNAPSHOT version if invoked with `-PisNightly=true` 4. Configures GPG signing of artifacts. I haven't touched the CircleCI and JS code yet. I'll do it in another diff. Changelog: [General] [Changed] - Setup publishing for Snapshot and Stable on Maven Reviewed By: mdvacca, cipolleschi Differential Revision: D40146212 fbshipit-source-id: 9321e16f6c18b35bc3ae785749d613085c56e7bc
1 parent 2934399 commit 0e2f090

File tree

8 files changed

+198
-91
lines changed

8 files changed

+198
-91
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ project.xcworkspace
3636
/ReactAndroid/gradle/
3737
/ReactAndroid/gradlew
3838
/ReactAndroid/gradlew.bat
39+
/ReactAndroid/external-artifacts/build/
40+
/ReactAndroid/external-artifacts/artifacts/
3941
/ReactAndroid/hermes-engine/build/
4042
/ReactAndroid/hermes-engine/.cxx/
4143
/template/android/app/build/

ReactAndroid/build.gradle

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ buildscript {
1414
plugins {
1515
id("com.android.library")
1616
id("com.facebook.react")
17-
id("maven-publish")
1817
id("de.undercouch.download")
18+
id("maven-publish")
1919
}
2020

2121
import com.facebook.react.tasks.internal.*
@@ -26,10 +26,10 @@ import java.nio.file.Paths
2626
import kotlin.Pair
2727

2828
import de.undercouch.gradle.tasks.download.Download
29-
import org.apache.tools.ant.taskdefs.condition.Os
30-
import org.apache.tools.ant.filters.ReplaceTokens
3129

32-
def AAR_OUTPUT_URL = "file://${projectDir}/../android"
30+
version = VERSION_NAME
31+
group = "com.facebook.react"
32+
3333
// We download various C++ open-source dependencies into downloads.
3434
// We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
3535
// After that we build native code from src/main/jni with module path pointing at third-party-ndk.
@@ -349,7 +349,7 @@ def reactNativeArchitectures() {
349349
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
350350
}
351351

352-
tasks.register("packageReactNdkLibsForBuck") {
352+
task packageReactNdkLibsForBuck(type: Copy) {
353353
dependsOn("mergeDebugNativeLibs")
354354
// Shared libraries (.so) are copied from the merged_native_libs folder instead
355355
from("$buildDir/intermediates/merged_native_libs/debug/out/lib/")
@@ -396,11 +396,11 @@ android {
396396
externalNativeBuild {
397397
cmake {
398398
arguments "-DREACT_COMMON_DIR=${reactNativeRootDir}/ReactCommon",
399-
"-DREACT_ANDROID_DIR=$projectDir",
400-
"-DREACT_BUILD_DIR=$buildDir",
401-
"-DANDROID_STL=c++_shared",
402-
"-DANDROID_TOOLCHAIN=clang",
403-
"-DANDROID_PLATFORM=android-21"
399+
"-DREACT_ANDROID_DIR=$projectDir",
400+
"-DREACT_BUILD_DIR=$buildDir",
401+
"-DANDROID_STL=c++_shared",
402+
"-DANDROID_TOOLCHAIN=clang",
403+
"-DANDROID_PLATFORM=android-21"
404404

405405
targets "reactnativejni",
406406
"jscexecutor",
@@ -430,7 +430,7 @@ android {
430430
}
431431
}
432432
ndk {
433-
abiFilters (*reactNativeArchitectures())
433+
abiFilters(*reactNativeArchitectures())
434434
}
435435
}
436436

@@ -554,7 +554,7 @@ android {
554554
publishing {
555555
multipleVariants {
556556
withSourcesJar()
557-
allVariants()
557+
includeBuildTypeValues('debug', 'release')
558558
}
559559
}
560560
}
@@ -611,54 +611,17 @@ react {
611611
codegenDir = file(findNodeModulePath(projectDir, "react-native-codegen") ?: "../packages/react-native-codegen/")
612612
}
613613

614-
afterEvaluate {
615-
publishing {
616-
publications {
617-
release(MavenPublication) {
618-
// We do a multi variant release
619-
from components.default
620-
621-
// You can then customize attributes of the publication as shown below.
622-
artifactId = POM_ARTIFACT_ID
623-
groupId = GROUP
624-
version = VERSION_NAME
625-
626-
pom {
627-
name = POM_NAME
628-
description = "A framework for building native apps with React"
629-
url = "https://github.com/facebook/react-native"
630-
631-
developers {
632-
developer {
633-
id = "facebook"
634-
name = "Facebook"
635-
}
636-
}
637-
638-
licenses {
639-
license {
640-
name = "MIT License"
641-
url = "https://github.com/facebook/react-native/blob/HEAD/LICENSE"
642-
distribution = "repo"
643-
}
644-
}
645-
646-
scm {
647-
url = "https://github.com/facebook/react-native.git"
648-
connection = "scm:git:https://github.com/facebook/react-native.git"
649-
developerConnection = "scm:git:[email protected]:facebook/react-native.git"
650-
}
651-
}
652-
}
653-
}
614+
apply plugin: "org.jetbrains.kotlin.android"
654615

655-
repositories {
656-
maven {
657-
name = "npm"
658-
url = AAR_OUTPUT_URL
659-
}
616+
/* Publishing Configuration */
617+
apply from: "./publish.gradle"
618+
619+
// We need to override the artifact ID as this project is called `ReactAndroid` but
620+
// the maven coordinates are on `react-native`.
621+
publishing {
622+
publications {
623+
getByName("release") {
624+
artifactId 'react-native'
660625
}
661626
}
662627
}
663-
664-
apply plugin: "org.jetbrains.kotlin.android"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
plugins {
9+
id("maven-publish")
10+
}
11+
12+
group = "com.facebook.react"
13+
version = parent.publishing_version
14+
configurations.maybeCreate("default")
15+
16+
// The artifact should be placed inside the `artifacts/hermes-ios.tar.gz` location.
17+
def hermesiOSArtifactFile = layout.projectDirectory.file('artifacts/hermes-ios.tar.gz')
18+
def hermesiOSArtifact = artifacts.add('default', hermesiOSArtifactFile) {
19+
type 'tgz'
20+
extension 'tar.gz'
21+
classifier 'hermes-ios'
22+
}
23+
24+
apply from: "../publish.gradle"
25+
26+
publishing {
27+
publications {
28+
getByName("release") {
29+
artifact hermesiOSArtifact
30+
}
31+
}
32+
}

ReactAndroid/gradle.properties

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
VERSION_NAME=1000.0.0
22
GROUP=com.facebook.react
33

4-
POM_NAME=ReactNative
5-
POM_ARTIFACT_ID=react-native
6-
POM_PACKAGING=aar
7-
84
# JVM Versions
95
ANDROIDX_APPCOMPAT_VERSION=1.4.1
106
ANDROIDX_AUTOFILL_VERSION=1.1.0

ReactAndroid/hermes-engine/build.gradle

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ plugins {
1111
id("de.undercouch.download")
1212
id("com.android.library")
1313
id("maven-publish")
14+
id("signing")
1415
}
1516

1617
group = "com.facebook.react"
@@ -56,10 +57,6 @@ def skipPrefabPublishing = System.getenv("REACT_NATIVE_HERMES_SKIP_PREFAB") != n
5657
// We inject the JSI directory used inside the Hermes build with the -DJSI_DIR config.
5758
def jsiDir = new File(reactNativeRootDir, "ReactCommon/jsi")
5859

59-
// The .aar is placed inside the ./android folder at the top level.
60-
// There it will be placed alongside the React Android .aar
61-
def AAR_OUTPUT_URL = "file://${rootDir}/android"
62-
6360
task downloadHermes(type: Download) {
6461
src("https://github.com/facebook/hermes/tarball/${hermesVersion}")
6562
onlyIfNewer(true)
@@ -234,27 +231,7 @@ afterEvaluate {
234231
}
235232
preBuild.dependsOn(buildHermes)
236233
preBuild.dependsOn(prepareHeadersForPrefab)
237-
// Needed as some of the native sources needs to be downloaded
238-
// before configureCMakeRelease/configureCMakeMinSizeRel could be executed.
239-
reactNativeArchitectures().each { architecture ->
240-
tasks.findByName("configureCMakeMinSizeRel[${architecture}]")?.configure { dependsOn(preBuild) }
241-
tasks.findByName("configureCMakeRelease[${architecture}]")?.configure { dependsOn(preBuild) }
242-
}
243-
configureCMakeRelease.dependsOn(preBuild)
244-
configureCMakeMinSizeRel.dependsOn(preBuild)
245-
246-
publishing {
247-
publications {
248-
release(MavenPublication) {
249-
from components.default
250-
artifactId = "hermes-engine"
251-
}
252-
}
253-
repositories {
254-
maven {
255-
name = "npm"
256-
url = AAR_OUTPUT_URL
257-
}
258-
}
259-
}
234+
prepareHeadersForPrefab.dependsOn(buildHermes)
260235
}
236+
237+
apply from: "../publish.gradle"

ReactAndroid/publish.gradle

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
apply plugin: 'maven-publish'
9+
apply plugin: 'signing'
10+
11+
def isNightly = findProperty("isNightly")?.toBoolean()
12+
def sonatypeUsername = findProperty("SONATYPE_USERNAME")
13+
def sonatypePassword = findProperty("SONATYPE_PASSWORD")
14+
def signingKey = findProperty("SIGNING_KEY")
15+
def signingPwd = findProperty("SIGNING_PWD")
16+
17+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
18+
def androidOutputUrl = "file://${reactAndroidProjectDir}/../android"
19+
20+
publishing {
21+
publications {
22+
release(MavenPublication) {
23+
afterEvaluate {
24+
// We do a multi variant release, so for Android libraries
25+
// we publish `components.release`
26+
if (plugins.hasPlugin("com.android.library")) {
27+
from components.default
28+
}
29+
}
30+
31+
// We populate the publishing version using the project version,
32+
// appending -SNAPSHOT if on nightly.
33+
if (isNightly) {
34+
version = this.version + "-SNAPSHOT"
35+
} else {
36+
version = this.version
37+
}
38+
39+
pom {
40+
name = "react-native"
41+
description = "A framework for building native apps with React"
42+
url = "https://github.com/facebook/react-native"
43+
44+
developers {
45+
developer {
46+
id = "facebook"
47+
name = "Facebook"
48+
}
49+
}
50+
51+
licenses {
52+
license {
53+
name = "MIT License"
54+
url = "https://github.com/facebook/react-native/blob/HEAD/LICENSE"
55+
distribution = "repo"
56+
}
57+
}
58+
59+
scm {
60+
url = "https://github.com/facebook/react-native.git"
61+
connection = "scm:git:https://github.com/facebook/react-native.git"
62+
developerConnection = "scm:git:[email protected]:facebook/react-native.git"
63+
}
64+
}
65+
}
66+
}
67+
68+
repositories {
69+
maven {
70+
name = "npm"
71+
url = androidOutputUrl
72+
}
73+
if (sonatypeUsername && sonatypePassword) {
74+
maven {
75+
name = "mavenCentral"
76+
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
77+
credentials {
78+
username = sonatypeUsername
79+
password = sonatypePassword
80+
}
81+
}
82+
maven {
83+
name = "mavenSnapshots"
84+
url = "https://oss.sonatype.org/content/repositories/snapshots/"
85+
credentials {
86+
username = sonatypeUsername
87+
password = sonatypePassword
88+
}
89+
}
90+
}
91+
}
92+
93+
if (signingKey && signingPwd) {
94+
logger.info("PGP Key found - Signing enabled")
95+
signing {
96+
useInMemoryPgpKeys(signingKey, signingPwd)
97+
sign(publishing.publications.release)
98+
}
99+
} else {
100+
logger.info("Signing disabled as the PGP key was not found")
101+
}
102+
}

build.gradle.kts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,34 @@ tasks.register("downloadAll") {
7474
dependsOn(":ReactAndroid:hermes-engine:dependencies")
7575
dependsOn(":ReactAndroid:hermes-engine:androidDependencies")
7676
}
77+
78+
tasks.register("publishAllInsideNpmPackage") {
79+
description =
80+
"Publish all the artifacts to be available inside the NPM package in the `android` folder."
81+
// Due to size constraints of NPM, we publish only react-native and hermes-engine inside
82+
// the NPM package.
83+
dependsOn(":ReactAndroid:installArchives")
84+
dependsOn(":ReactAndroid:hermes-engine:installArchives")
85+
}
86+
87+
tasks.register("publishAllToMavenLocal") {
88+
description = "Publish all the artifacts to be available inside Maven Local."
89+
dependsOn(":ReactAndroid:publishToMavenLocal")
90+
dependsOn(":ReactAndroid:external-artifacts:publishToMavenLocal")
91+
dependsOn(":ReactAndroid:hermes-engine:publishToMavenLocal")
92+
}
93+
94+
tasks.register("publishAllToMavenSnapshots") {
95+
description =
96+
"Publish all the artifacts as a snapshot (used for testing/nightly) on Maven Central."
97+
dependsOn(":ReactAndroid:publishAllPublicationsToMavenSnapshotsRepository")
98+
dependsOn(":ReactAndroid:external-artifacts:publishAllPublicationsToMavenSnapshotsRepository")
99+
dependsOn(":ReactAndroid:hermes-engine:publishAllPublicationsToMavenSnapshotsRepository")
100+
}
101+
102+
tasks.register("publishAllToMavenCentral") {
103+
description = "Publish all the artifacts as a release on Maven Central."
104+
dependsOn(":ReactAndroid:publishAllPublicationsToMavenCentralRepository")
105+
dependsOn(":ReactAndroid:external-artifacts:publishAllPublicationsToMavenCentralRepository")
106+
dependsOn(":ReactAndroid:hermes-engine:publishAllPublicationsToMavenCentralRepository")
107+
}

settings.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ pluginManagement {
1313
}
1414
}
1515

16-
include(":ReactAndroid", ":ReactAndroid:hermes-engine", ":packages:rn-tester:android:app")
16+
include(
17+
":ReactAndroid",
18+
":ReactAndroid:hermes-engine",
19+
":ReactAndroid:external-artifacts",
20+
":packages:rn-tester:android:app")
1721

1822
// Include this to enable codegen Gradle plugin.
1923
includeBuild("packages/react-native-gradle-plugin/")

0 commit comments

Comments
 (0)