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 061a56bdc37bf6..9f8759f0dbc624 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 @@ -15,17 +15,37 @@ import com.facebook.react.tasks.BuildCodegenCLITask import com.facebook.react.tasks.GenerateCodegenArtifactsTask import com.facebook.react.tasks.GenerateCodegenSchemaTask import java.io.File +import kotlin.system.exitProcess import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.internal.jvm.Jvm class ReactPlugin : Plugin { override fun apply(project: Project) { + checkJvmVersion() val extension = project.extensions.create("react", ReactExtension::class.java, project) applyAppPlugin(project, extension) applyCodegenPlugin(project, extension) } + private fun checkJvmVersion() { + val jvmVersion = Jvm.current()?.javaVersion?.majorVersion + if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) { + println("\n\n\n") + println( + "**************************************************************************************************************") + println("\n\n") + println("ERROR: requires JDK11 or higher.") + println("Incompatible major version detected: '" + jvmVersion + "'") + println("\n\n") + println( + "**************************************************************************************************************") + println("\n\n\n") + exitProcess(1) + } + } + private fun applyAppPlugin(project: Project, config: ReactExtension) { project.afterEvaluate { if (config.applyAppPlugin.getOrElse(false)) { diff --git a/react.gradle b/react.gradle index 0ace9be826f805..4c6a5151343a97 100644 --- a/react.gradle +++ b/react.gradle @@ -6,6 +6,7 @@ */ import org.apache.tools.ant.taskdefs.condition.Os +import org.gradle.internal.jvm.Jvm def config = project.hasProperty("react") ? project.react : [:]; @@ -129,6 +130,19 @@ android { } } +def jvmVersion = Jvm.current().javaVersion.majorVersion +if (jvmVersion.toInteger() <= 8) { + println "\n\n\n" + println "**************************************************************************************************************" + println "\n\n" + println "ERROR: requires JDK11 or higher." + println "Incompatible major version detected: '" + jvmVersion + "'" + println "\n\n" + println "**************************************************************************************************************" + println "\n\n\n" + System.exit(1) +} + afterEvaluate { def isAndroidLibrary = plugins.hasPlugin("com.android.library") def variants = isAndroidLibrary ? android.libraryVariants : android.applicationVariants