From a8f4b6465fe6f4fb853f09acd238bd9f96f0efab Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Tue, 28 Apr 2020 14:30:02 +0300 Subject: [PATCH] Common java version method (#1965) --- build.gradle | 9 +++------ buildSrc/src/main/kotlin/JavaVersion.kt | 7 +++++++ ui/kotlinx-coroutines-javafx/build.gradle | 10 ++-------- 3 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 buildSrc/src/main/kotlin/JavaVersion.kt diff --git a/build.gradle b/build.gradle index c679109ca3..08a241a411 100644 --- a/build.gradle +++ b/build.gradle @@ -227,7 +227,7 @@ if (build_snapshot_train) { * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files * for JVM-only projects. * - * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it + * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it * to have out "project" dependency back. */ configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) { @@ -278,11 +278,8 @@ println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompi // --------------- Publish only from under JDK11+ --------------- task checkJdkForPublish { doFirst { - String javaVersion = System.properties["java.version"] - int i = javaVersion.indexOf('.') - int javaVersionMajor = (i < 0 ? javaVersion : javaVersion.substring(0, i)).toInteger() - if (javaVersionMajor < 11) { - throw new GradleException("Project can be build for publishing only under JDK 11+, but found ${javaVersion}") + if (JavaVersionKt.javaVersionMajor < 11) { + throw new GradleException("Project can be build for publishing only under JDK 11+, but found ${JavaVersionKt.javaVersion}") } } } diff --git a/buildSrc/src/main/kotlin/JavaVersion.kt b/buildSrc/src/main/kotlin/JavaVersion.kt new file mode 100644 index 0000000000..2fbefce5e3 --- /dev/null +++ b/buildSrc/src/main/kotlin/JavaVersion.kt @@ -0,0 +1,7 @@ +val javaVersion: String + get() = System.getProperty("java.version")!! + +val javaVersionMajor: Int + get() = javaVersion + .substringBefore(".") + .toInt() diff --git a/ui/kotlinx-coroutines-javafx/build.gradle b/ui/kotlinx-coroutines-javafx/build.gradle index 9d1c128239..daabda40ff 100644 --- a/ui/kotlinx-coroutines-javafx/build.gradle +++ b/ui/kotlinx-coroutines-javafx/build.gradle @@ -2,16 +2,10 @@ * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -static int javaVersionMajor() { - String javaVersion = System.properties["java.version"] - int i = javaVersion.indexOf('.') - return (i < 0 ? javaVersion : javaVersion.substring(0, i)).toInteger() -} - // JDK11+ does not bundle JavaFx and the plugin for JavaFx support is compiled with class file version 55.0 (JDK 11) -if (javaVersionMajor() >= 11) { +if (JavaVersionKt.javaVersionMajor >= 11) { apply plugin: 'org.openjfx.javafxplugin' - + javafx { version = javafx_version modules = ['javafx.controls']