From e47cb35409edf8752eba0a72393ecc6505bb06b9 Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Tue, 12 May 2020 18:33:04 +0300 Subject: [PATCH] Add project JDK convention (#1984) --- build.gradle | 15 +-------------- buildSrc/src/main/kotlin/Idea.kt | 4 ++++ buildSrc/src/main/kotlin/JavaVersion.kt | 7 ------- .../src/main/kotlin/jdk-convention.gradle.kts | 10 ++++++++++ settings.gradle | 3 +++ ui/kotlinx-coroutines-javafx/build.gradle | 15 +++++++-------- 6 files changed, 25 insertions(+), 29 deletions(-) create mode 100644 buildSrc/src/main/kotlin/Idea.kt delete mode 100644 buildSrc/src/main/kotlin/JavaVersion.kt create mode 100644 buildSrc/src/main/kotlin/jdk-convention.gradle.kts diff --git a/build.gradle b/build.gradle index 032c4e798b..bc4dd36afc 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ */ import org.jetbrains.kotlin.konan.target.HostManager +apply plugin: 'jdk-convention' apply from: rootProject.file("gradle/experimental.gradle") def rootModule = "kotlinx.coroutines" @@ -69,7 +70,6 @@ buildscript { classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version" classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version" classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version" - classpath "org.openjfx:javafx-plugin:$javafx_plugin_version" classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version" // JMH plugins @@ -264,22 +264,9 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) { // Report Kotlin compiler version when building project println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION") -// --------------- Publish only from under JDK11+ --------------- -task checkJdkForPublish { - doFirst { - if (JavaVersionKt.javaVersionMajor < 11) { - throw new GradleException("Project can be build for publishing only under JDK 11+, but found ${JavaVersionKt.javaVersion}") - } - } -} - // --------------- Configure sub-projects that are published --------------- def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true) -publishTasks.each { - it.dependsOn checkJdkForPublish -} - task deploy(dependsOn: publishTasks) apply plugin: 'base' diff --git a/buildSrc/src/main/kotlin/Idea.kt b/buildSrc/src/main/kotlin/Idea.kt new file mode 100644 index 0000000000..802b387b0d --- /dev/null +++ b/buildSrc/src/main/kotlin/Idea.kt @@ -0,0 +1,4 @@ +object Idea { + val active: Boolean + get() = System.getProperty("idea.active") == "true" +} diff --git a/buildSrc/src/main/kotlin/JavaVersion.kt b/buildSrc/src/main/kotlin/JavaVersion.kt deleted file mode 100644 index 2fbefce5e3..0000000000 --- a/buildSrc/src/main/kotlin/JavaVersion.kt +++ /dev/null @@ -1,7 +0,0 @@ -val javaVersion: String - get() = System.getProperty("java.version")!! - -val javaVersionMajor: Int - get() = javaVersion - .substringBefore(".") - .toInt() diff --git a/buildSrc/src/main/kotlin/jdk-convention.gradle.kts b/buildSrc/src/main/kotlin/jdk-convention.gradle.kts new file mode 100644 index 0000000000..8bc1abf17d --- /dev/null +++ b/buildSrc/src/main/kotlin/jdk-convention.gradle.kts @@ -0,0 +1,10 @@ +import org.gradle.api.JavaVersion + +if (!JavaVersion.current().isJava11Compatible) { + val message = "Project required JDK 11+, but found ${JavaVersion.current()}" + if (Idea.active) { + logger.error(message) + } else { + throw GradleException(message) + } +} diff --git a/settings.gradle b/settings.gradle index 2f0e661b4c..ae49f16d1d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,6 +4,9 @@ pluginManagement { plugins { + id "org.openjfx.javafxplugin" version javafx_plugin_version + + // JMH id "net.ltgt.apt" version "0.21" id "me.champeau.gradle.jmh" version "0.5.0-rc-2" } diff --git a/ui/kotlinx-coroutines-javafx/build.gradle b/ui/kotlinx-coroutines-javafx/build.gradle index daabda40ff..77f1b09650 100644 --- a/ui/kotlinx-coroutines-javafx/build.gradle +++ b/ui/kotlinx-coroutines-javafx/build.gradle @@ -2,15 +2,14 @@ * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -// JDK11+ does not bundle JavaFx and the plugin for JavaFx support is compiled with class file version 55.0 (JDK 11) -if (JavaVersionKt.javaVersionMajor >= 11) { - apply plugin: 'org.openjfx.javafxplugin' +plugins { + id 'org.openjfx.javafxplugin' +} - javafx { - version = javafx_version - modules = ['javafx.controls'] - configuration = 'compile' - } +javafx { + version = javafx_version + modules = ['javafx.controls'] + configuration = 'compile' } task checkJdk8() {