Skip to content

Commit 52d2065

Browse files
authored
[LOCAL] Make sure Java Toolchain and source/target level is applied to all projects (#37576)
1 parent e0c88fe commit 52d2065

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibili
1919
import com.facebook.react.utils.DependencyUtils.configureDependencies
2020
import com.facebook.react.utils.DependencyUtils.configureRepositories
2121
import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
22+
import com.facebook.react.utils.JdkConfiguratorUtils.configureJavaToolChains
2223
import com.facebook.react.utils.JsonUtils
2324
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
2425
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
@@ -78,6 +79,9 @@ class ReactPlugin : Plugin<Project> {
7879
project.pluginManager.withPlugin("com.android.library") {
7980
configureCodegen(project, extension, rootExtension, isLibrary = true)
8081
}
82+
83+
// App and Library Configurations
84+
configureJavaToolChains(project)
8185
}
8286

8387
private fun checkJvmVersion(project: Project) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
package com.facebook.react.utils
9+
10+
import com.android.build.api.variant.AndroidComponentsExtension
11+
import com.facebook.react.utils.PropertyUtils.INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT
12+
import org.gradle.api.Action
13+
import org.gradle.api.JavaVersion
14+
import org.gradle.api.Project
15+
import org.gradle.api.plugins.AppliedPlugin
16+
17+
internal object JdkConfiguratorUtils {
18+
/**
19+
* Function that takes care of configuring the JDK toolchain for all the projects projects. As we
20+
* do decide the JDK version based on the AGP version that RNGP brings over, here we can safely
21+
* configure the toolchain to 11.
22+
*/
23+
fun configureJavaToolChains(input: Project) {
24+
if (input.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
25+
return
26+
}
27+
input.rootProject.allprojects { project ->
28+
val action =
29+
Action<AppliedPlugin> {
30+
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl {
31+
ext ->
32+
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_11
33+
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_11
34+
}
35+
}
36+
project.pluginManager.withPlugin("com.android.application", action)
37+
project.pluginManager.withPlugin("com.android.library", action)
38+
}
39+
}
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
package com.facebook.react.utils
9+
10+
/** Collection of all the Gradle Propreties that are accepted by React Native Gradle Plugin. */
11+
object PropertyUtils {
12+
13+
/**
14+
* Internal Property that acts as a killswitch to configure the JDK version and align it for app
15+
* and all the libraries.
16+
*/
17+
const val INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT = "react.internal.disableJavaVersionAlignment"
18+
}

0 commit comments

Comments
 (0)