From a86b127859804e8176bbfb5596d47437dd874d7b Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 07:45:17 -0800 Subject: [PATCH] RNGP - Correctly Support Gradle Configuration Cache (#35455) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35455 This little change allows to support Gradle Configuration cache in user projects: https://docs.gradle.org/current/userguide/configuration_cache.html It allows to save several seconds on the build time. We'll keep it disabled for now, but Gradle plans to enable it by default for everyone in the future, so this changes makes us ready for it. Changelog: [Internal] [Changed] - RNGP - Correctly Support Gradle Configuration Cache Reviewed By: cipolleschi Differential Revision: D41519506 fbshipit-source-id: 6252546e811deb0777c0aab5332291368be7fa8f --- .../src/main/kotlin/com/facebook/react/ReactPlugin.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 8538eaa9941d48..b6523cdf607c1b 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -96,7 +96,8 @@ class ReactPlugin : Plugin { // Please note that appNeedsCodegen is triggering a read of the package.json at // configuration time as we need to feed the onlyIf condition of this task. // Therefore, the appNeedsCodegen needs to be invoked inside this lambda. - it.onlyIf { isLibrary || project.needsCodegenFromPackageJson(extension) } + val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension) + it.onlyIf { isLibrary || needsCodegenFromPackageJson } } // We create the task to produce schema from JS files. @@ -120,7 +121,8 @@ class ReactPlugin : Plugin { } else { it.jsRootDir.set(extension.jsRootDir) } - it.onlyIf { isLibrary || project.needsCodegenFromPackageJson(parsedPackageJson) } + val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension) + it.onlyIf { isLibrary || needsCodegenFromPackageJson } } // We create the task to generate Java code from schema. @@ -139,7 +141,8 @@ class ReactPlugin : Plugin { // Please note that appNeedsCodegen is triggering a read of the package.json at // configuration time as we need to feed the onlyIf condition of this task. // Therefore, the appNeedsCodegen needs to be invoked inside this lambda. - it.onlyIf { isLibrary || project.needsCodegenFromPackageJson(extension) } + val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension) + it.onlyIf { isLibrary || needsCodegenFromPackageJson } } // We update the android configuration to include the generated sources.