Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Java toolchains per project #41306

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class ReactPlugin : Plugin<Project> {
configureBuildConfigFieldsForApp(project, extension)
configureDevPorts(project)
configureBackwardCompatibilityReactMap(project)
configureJavaToolChains(project)

project.extensions.getByType(AndroidComponentsExtension::class.java).apply {
onVariants(selector().all()) { variant ->
Expand All @@ -87,6 +86,9 @@ class ReactPlugin : Plugin<Project> {
project.pluginManager.withPlugin("com.android.library") {
configureCodegen(project, extension, rootExtension, isLibrary = true)
}

// Library and App Configurations
configureJavaToolChains(project)
}

private fun checkJvmVersion(project: Project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppliedPlugin> {
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext
->
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17
}
val action =
Action<AppliedPlugin> {
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)
}
}
}