From 7e70c93cbf6d62dbc53714e4c5b72540b84af201 Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Thu, 1 Jul 2021 15:21:42 +0200 Subject: [PATCH] Allow to avoid using JDK 1.6 and JDK 1.7 in the repo. This behaviour could be enabled via adding 'kotlin.build.isObsoleteJdkOverrideEnabled=true' to the 'local.properties' file. ^KT-46972 Fixed --- ReadMe.md | 4 +++ .../src/main/kotlin/BuildPropertiesExt.kt | 4 +++ buildSrc/src/main/kotlin/JvmToolchain.kt | 32 +++++++++++++------ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index f356a69e71c..9302ab488e5 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -56,6 +56,10 @@ Alternatively, it is still possible to only provide required JDKs via environmen from environmental variables - disable Gradle toolchain auto-detection by passing `-Porg.gradle.java.installations.auto-detect=false` option (or put it into `$GRADLE_USER_HOME/gradle.properties`). +For local development, if you're not working on bytecode generation or the standard library, it's OK to avoid installing JDK 1.6 and JDK 1.7. +Add `kotlin.build.isObsoleteJdkOverrideEnabled=true` to the `local.properties` file, so build will only use JDK 1.8+. Note, that in this +case, build will have Gradle remote build cache misses for some tasks. + Note: The JDK 6 for MacOS is not available on Oracle's site. You can install it by ```bash diff --git a/buildSrc/src/main/kotlin/BuildPropertiesExt.kt b/buildSrc/src/main/kotlin/BuildPropertiesExt.kt index 3adb3ddfff8..c02f7ae5c2d 100644 --- a/buildSrc/src/main/kotlin/BuildPropertiesExt.kt +++ b/buildSrc/src/main/kotlin/BuildPropertiesExt.kt @@ -20,3 +20,7 @@ val KotlinBuildProperties.jarCompression: Boolean get() = getBoolean("kotlin.bui val KotlinBuildProperties.ignoreTestFailures: Boolean get() = getBoolean("ignoreTestFailures", isTeamcityBuild) val KotlinBuildProperties.disableWerror: Boolean get() = getBoolean("kotlin.build.disable.werror", false) + +val KotlinBuildProperties.isObsoleteJdkOverrideEnabled: Boolean + get() = !isTeamcityBuild && + getBoolean("kotlin.build.isObsoleteJdkOverrideEnabled", false) diff --git a/buildSrc/src/main/kotlin/JvmToolchain.kt b/buildSrc/src/main/kotlin/JvmToolchain.kt index cb46d15d4bb..5c629a1fabe 100644 --- a/buildSrc/src/main/kotlin/JvmToolchain.kt +++ b/buildSrc/src/main/kotlin/JvmToolchain.kt @@ -10,16 +10,18 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile enum class JdkMajorVersion( val majorVersion: Int, + val targetName: String = majorVersion.toString(), + val overrideMajorVersion: Int? = null, private val mandatory: Boolean = true ) { - JDK_1_6(6), - JDK_1_7(7), - JDK_1_8(8), + JDK_1_6(6, targetName = "1.6", overrideMajorVersion = 8), + JDK_1_7(7, targetName = "1.7", overrideMajorVersion = 8), + JDK_1_8(8, targetName = "1.8"), JDK_9(9), - JDK_10(10, false), - JDK_11(11, false), - JDK_15(15, false), - JDK_16(16, false); + JDK_10(10, mandatory = false), + JDK_11(11, mandatory = false), + JDK_15(15, mandatory = false), + JDK_16(16, mandatory = false); fun isMandatory(): Boolean = mandatory } @@ -34,9 +36,19 @@ fun Project.configureJvmToolchain( plugins.withId("org.jetbrains.kotlin.jvm") { val kotlinExtension = extensions.getByType() - kotlinExtension.jvmToolchain { - (this as JavaToolchainSpec).languageVersion - .set(JavaLanguageVersion.of(jdkVersion.majorVersion)) + if (project.kotlinBuildProperties.isObsoleteJdkOverrideEnabled && + jdkVersion.overrideMajorVersion != null + ) { + kotlinExtension.jvmToolchain { + (this as JavaToolchainSpec).languageVersion + .set(JavaLanguageVersion.of(jdkVersion.overrideMajorVersion)) + } + updateJvmTarget(jdkVersion.targetName) + } else { + kotlinExtension.jvmToolchain { + (this as JavaToolchainSpec).languageVersion + .set(JavaLanguageVersion.of(jdkVersion.majorVersion)) + } } tasks