From 48b86bba691436b3604733f9bfadaf7b2f29963c Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 10 Jun 2019 21:05:55 +0300 Subject: [PATCH] Check JDK env vars once during configuration when not syncing Previous code (callback in `beforeTask`) was added to allow opening project without setting up all env. variables. This change simplifies the code and avoids a callback, while keeping the ability to open the project without setting up all variables by checking `kotlinBuildProperties.isInIdeaSync` --- build.gradle.kts | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 833c345c5d6..f66070484f1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -122,30 +122,19 @@ extra["JDK_9"] = jdkPath("9") extra["JDK_10"] = jdkPath("10") extra["JDK_11"] = jdkPath("11") -gradle.taskGraph.beforeTask() { +// allow opening the project without setting up all env variables (see KT-26413) +if (!kotlinBuildProperties.isInIdeaSync) { checkJDK() } -var jdkChecked: Boolean = false fun checkJDK() { - if (jdkChecked) { - return + val missingEnvVars = JdkMajorVersion.values() + .filter { it.isMandatory() && extra[it.name] == jdkNotFoundConst } + .mapTo(ArrayList()) { it.name } + + if (missingEnvVars.isNotEmpty()) { + throw GradleException("Required environment variables are missing: ${missingEnvVars.joinToString()}") } - - val unpresentJdks = JdkMajorVersion.values() - .filter { it.isMandatory() } - .map { it.name } - .filter { extra[it] == jdkNotFoundConst } - .toList() - - if (unpresentJdks.isNotEmpty()) { - throw GradleException("Please set environment variable" + - (if (unpresentJdks.size > 1) "s" else "") + - ": " + unpresentJdks.joinToString() + - " to point to corresponding JDK installation.") - } - - jdkChecked = true } rootProject.apply {