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 5709501f3b594e..36b62611c3f6c2 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 @@ -71,7 +71,6 @@ class ReactPlugin : Plugin { configureBuildConfigFieldsForApp(project, extension) configureDevPorts(project) configureBackwardCompatibilityReactMap(project) - configureJavaToolChains(project) project.extensions.getByType(AndroidComponentsExtension::class.java).apply { onVariants(selector().all()) { variant -> @@ -87,6 +86,9 @@ class ReactPlugin : Plugin { project.pluginManager.withPlugin("com.android.library") { configureCodegen(project, extension, rootExtension, isLibrary = true) } + + // Library and App Configurations + configureJavaToolChains(project) } private fun checkJvmVersion(project: Project) { diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt index 0d557148eb885e..1afe777d7a1c42 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt @@ -17,36 +17,30 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension internal object JdkConfiguratorUtils { /** - * Function that takes care of configuring the JDK toolchain for all the projects projects. As we - * do decide the JDK version based on the AGP version that RNGP brings over, here we can safely + * Function that takes care of configuring the JDK toolchain for the project. As we do + * decide the JDK version based on the AGP version that RNGP brings over, here we can safely * configure the toolchain to 17. */ - fun configureJavaToolChains(input: Project) { + fun configureJavaToolChains(project: Project) { // Check at the app level if react.internal.disableJavaVersionAlignment is set. - if (input.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) { + if (project.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) { return } - input.rootProject.allprojects { project -> - // Allows every single module to set react.internal.disableJavaVersionAlignment also. - if (project.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) { - return@allprojects - } - val action = - Action { - project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext - -> - ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17 - ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17 - } + val action = + Action { + project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext + -> + ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17 + ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17 } - project.pluginManager.withPlugin("com.android.application", action) - project.pluginManager.withPlugin("com.android.library", action) - project.pluginManager.withPlugin("org.jetbrains.kotlin.android") { - project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17) - } - project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17) - } + } + project.pluginManager.withPlugin("com.android.application", action) + project.pluginManager.withPlugin("com.android.library", action) + project.pluginManager.withPlugin("org.jetbrains.kotlin.android") { + project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17) + } + project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17) } } }