From bd4aec869b846abcff82aa773a9a7ded641b1805 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 23 Jul 2024 08:12:42 -0700 Subject: [PATCH] RNGP - Do not attempt to load JSC from other repositories (#45598) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45598 I've noticed we attempt to load JSC from the Sonatype Snapshot repository. That is inefficient as we already know that JSC is available only inside node modules. This change makes the repository resolution stricter by better specifying which repo can download which dependency. Changelog: [Internal] [Changed] - Do not attempt to load JSC from other repositories Reviewed By: cipolleschi Differential Revision: D60116002 fbshipit-source-id: 21a2213708f5b0103860a59f3342f1bc0f59cdb9 --- .../facebook/react/utils/DependencyUtils.kt | 50 +++++++++++++++---- .../rn-tester/android/app/build.gradle.kts | 7 ++- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt index aedd296d40eea5..2a2f242c31ca26 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt @@ -29,13 +29,17 @@ internal object DependencyUtils { with(eachProject) { if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) { val mavenLocalRepoPath = property(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO) as String - mavenRepoFromURI(File(mavenLocalRepoPath).toURI()) + mavenRepoFromURI(File(mavenLocalRepoPath).toURI()) { repo -> + repo.content { it.excludeGroup("org.webkit") } + } } // We add the snapshot for users on nightlies. - mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/") + mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/") { repo -> + repo.content { it.excludeGroup("org.webkit") } + } repositories.mavenCentral { repo -> // We don't want to fetch JSC from Maven Central as there are older versions there. - repo.content { it.excludeModule("org.webkit", "android-jsc") } + repo.content { it.excludeGroup("org.webkit") } // If the user provided a react.internal.mavenLocalRepo, do not attempt to load // anything from Maven Central that is react related. @@ -44,9 +48,23 @@ internal object DependencyUtils { } } // Android JSC is installed from npm - mavenRepoFromURI(File(reactNativeDir, "../jsc-android/dist").toURI()) - repositories.google() - mavenRepoFromUrl("https://www.jitpack.io") + mavenRepoFromURI(File(reactNativeDir, "../jsc-android/dist").toURI()) { repo -> + repo.content { it.includeGroup("org.webkit") } + } + repositories.google { repo -> + repo.content { + // We don't want to fetch JSC or React from Google + it.excludeGroup("org.webkit") + it.excludeGroup("com.facebook.react") + } + } + mavenRepoFromUrl("https://www.jitpack.io") { repo -> + repo.content { + // We don't want to fetch JSC or React from JitPack + it.excludeGroup("org.webkit") + it.excludeGroup("com.facebook.react") + } + } } } } @@ -134,9 +152,21 @@ internal object DependencyUtils { return Pair(versionString, groupString) } - fun Project.mavenRepoFromUrl(url: String): MavenArtifactRepository = - project.repositories.maven { it.url = URI.create(url) } + fun Project.mavenRepoFromUrl( + url: String, + action: (MavenArtifactRepository) -> Unit = {} + ): MavenArtifactRepository = + project.repositories.maven { + it.url = URI.create(url) + action(it) + } - fun Project.mavenRepoFromURI(uri: URI): MavenArtifactRepository = - project.repositories.maven { it.url = uri } + fun Project.mavenRepoFromURI( + uri: URI, + action: (MavenArtifactRepository) -> Unit = {} + ): MavenArtifactRepository = + project.repositories.maven { + it.url = uri + action(it) + } } diff --git a/packages/rn-tester/android/app/build.gradle.kts b/packages/rn-tester/android/app/build.gradle.kts index 6af90f8bf68352..bcc1b40e4bbc63 100644 --- a/packages/rn-tester/android/app/build.gradle.kts +++ b/packages/rn-tester/android/app/build.gradle.kts @@ -84,7 +84,12 @@ fun reactNativeArchitectures(): List { return value?.toString()?.split(",") ?: listOf("armeabi-v7a", "x86", "x86_64", "arm64-v8a") } -repositories { maven { url = rootProject.file("node_modules/jsc-android/dist").toURI() } } +repositories { + maven { + url = rootProject.file("node_modules/jsc-android/dist").toURI() + content { includeGroup("org.webkit") } + } +} android { compileSdk = libs.versions.compileSdk.get().toInt()