Prohibit JVM target 1.6

But still compile stdlib, reflect, kotlin.test and scripting runtimes
with JVM target 1.6 to simplify migration from Kotlin 1.6 to 1.7.

 #KT-45165 Fixed
This commit is contained in:
Alexander Udalov
2022-04-06 21:27:58 +02:00
parent 1e800b8e18
commit 2e515f3945
40 changed files with 63 additions and 16 deletions
@@ -37,7 +37,7 @@ open class DefaultValues(val defaultValue: String, val possibleValues: List<Stri
object JvmTargetVersions : DefaultValues( object JvmTargetVersions : DefaultValues(
"null", "null",
JvmTarget.values().map { "\"${it.description}\"" } JvmTarget.supportedValues().map { "\"${it.description}\"" }
) )
object JsEcmaVersions : DefaultValues( object JsEcmaVersions : DefaultValues(
@@ -75,7 +75,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@Argument( @Argument(
value = "-jvm-target", value = "-jvm-target",
valueDescription = "<version>", valueDescription = "<version>",
description = "Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, ..., 18), default is 1.8" description = "Target version of the generated JVM bytecode (1.8, 9, 10, ..., 18), default is 1.8"
) )
var jvmTarget: String? by NullableStringFreezableVar(null) var jvmTarget: String? by NullableStringFreezableVar(null)
@@ -466,7 +466,8 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
@Argument( @Argument(
value = "-Xsuppress-deprecated-jvm-target-warning", value = "-Xsuppress-deprecated-jvm-target-warning",
description = "Suppress deprecation warning about deprecated JVM target versions" description = "Suppress deprecation warning about deprecated JVM target versions.\n" +
"This option has no effect and will be deleted in a future version."
) )
var suppressDeprecatedJvmTargetWarning: Boolean by FreezableVar(false) var suppressDeprecatedJvmTargetWarning: Boolean by FreezableVar(false)
@@ -56,10 +56,10 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
val jvmTarget = JvmTarget.fromString(jvmTargetValue) val jvmTarget = JvmTarget.fromString(jvmTargetValue)
if (jvmTarget != null) { if (jvmTarget != null) {
put(JVMConfigurationKeys.JVM_TARGET, jvmTarget) put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
if (jvmTarget == JvmTarget.JVM_1_6 && !arguments.suppressDeprecatedJvmTargetWarning) { if (jvmTarget == JvmTarget.JVM_1_6 && !isJvmTarget6Allowed()) {
messageCollector.report( messageCollector.report(
STRONG_WARNING, ERROR,
"JVM target 1.6 is deprecated and will be removed in a future release. Please migrate to JVM target 1.8 or above" "JVM target 1.6 is no longer supported. Please migrate to JVM target 1.8 or above"
) )
} }
} else { } else {
@@ -353,3 +353,6 @@ private val CompilerConfiguration.messageCollector: MessageCollector
private fun getJavaVersion(): Int = private fun getJavaVersion(): Int =
System.getProperty("java.specification.version")?.substringAfter('.')?.toIntOrNull() ?: 6 System.getProperty("java.specification.version")?.substringAfter('.')?.toIntOrNull() ?: 6
private fun isJvmTarget6Allowed(): Boolean =
K2JVMCompiler::class.java.classLoader.getResource("META-INF/unsafe-allow-jvm6") != null
@@ -55,5 +55,8 @@ enum class JvmTarget(
return if (platformDescription != null) "JVM target $platformDescription" return if (platformDescription != null) "JVM target $platformDescription"
else "JVM bytecode version $majorVersion" else "JVM bytecode version $majorVersion"
} }
fun supportedValues(): List<JvmTarget> =
values().asList() - JVM_1_6
} }
} }
+2 -1
View File
@@ -131,7 +131,8 @@ where advanced options include:
Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl). Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl).
Default value is 'enable' Default value is 'enable'
-Xsuppress-deprecated-jvm-target-warning -Xsuppress-deprecated-jvm-target-warning
Suppress deprecation warning about deprecated JVM target versions Suppress deprecation warning about deprecated JVM target versions.
This option has no effect and will be deleted in a future version.
-Xsuppress-missing-builtins-error -Xsuppress-missing-builtins-error
Suppress the "cannot access built-in declaration" error (useful with -no-stdlib) Suppress the "cannot access built-in declaration" error (useful with -no-stdlib)
-Xtype-enhancement-improvements-strict-mode -Xtype-enhancement-improvements-strict-mode
+1 -1
View File
@@ -6,7 +6,7 @@ where possible options include:
-include-runtime Include Kotlin runtime into the resulting JAR -include-runtime Include Kotlin runtime into the resulting JAR
-java-parameters Generate metadata for Java 1.8 reflection on method parameters -java-parameters Generate metadata for Java 1.8 reflection on method parameters
-jdk-home <path> Include a custom JDK from the specified location into the classpath instead of the default JAVA_HOME -jdk-home <path> Include a custom JDK from the specified location into the classpath instead of the default JAVA_HOME
-jvm-target <version> Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, ..., 18), default is 1.8 -jvm-target <version> Target version of the generated JVM bytecode (1.8, 9, 10, ..., 18), default is 1.8
-module-name <name> Name of the generated .kotlin_module file -module-name <name> Name of the generated .kotlin_module file
-no-jdk Don't automatically include the Java runtime into the classpath -no-jdk Don't automatically include the Java runtime into the classpath
-no-reflect Don't automatically include Kotlin reflection into the classpath -no-reflect Don't automatically include Kotlin reflection into the classpath
+2 -2
View File
@@ -1,2 +1,2 @@
warning: JVM target 1.6 is deprecated and will be removed in a future release. Please migrate to JVM target 1.8 or above error: JVM target 1.6 is no longer supported. Please migrate to JVM target 1.8 or above
OK COMPILATION_ERROR
+1 -1
View File
@@ -1,3 +1,3 @@
warning: JVM target 1.6 is deprecated and will be removed in a future release. Please migrate to JVM target 1.8 or above error: JVM target 1.6 is no longer supported. Please migrate to JVM target 1.8 or above
error: '-Xjvm-default=all' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8' error: '-Xjvm-default=all' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8'
COMPILATION_ERROR COMPILATION_ERROR
@@ -8,6 +8,7 @@ project.updateJvmTarget("1.6")
dependencies { dependencies {
api(kotlinStdlib()) api(kotlinStdlib())
testApi(project(":kotlin-test:kotlin-test-jvm")) testApi(project(":kotlin-test:kotlin-test-jvm"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
@@ -7,6 +7,7 @@ project.configureJvmToolchain(JdkMajorVersion.JDK_1_6)
dependencies { dependencies {
api(project(":core:compiler.common")) api(project(":core:compiler.common"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -9,6 +9,7 @@ dependencies {
api(project(":core:util.runtime")) api(project(":core:util.runtime"))
api(kotlinStdlib()) api(kotlinStdlib())
api(project(":kotlin-annotations-jvm")) api(project(":kotlin-annotations-jvm"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -13,6 +13,7 @@ dependencies {
api(project(":core:deserialization.common.jvm")) api(project(":core:deserialization.common.jvm"))
api(project(":core:util.runtime")) api(project(":core:util.runtime"))
api(commonDependency("javax.inject")) api(commonDependency("javax.inject"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
@@ -26,6 +26,8 @@ dependencies {
testApi(projectTests(":generators:test-generator")) testApi(projectTests(":generators:test-generator"))
testApi(intellijCore()) testApi(intellijCore())
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -10,6 +10,7 @@ dependencies {
api(project(":core:util.runtime")) api(project(":core:util.runtime"))
api(kotlinStdlib()) api(kotlinStdlib())
api(project(":kotlin-annotations-jvm")) api(project(":kotlin-annotations-jvm"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
@@ -9,6 +9,7 @@ dependencies {
api(project(":core:metadata.jvm")) api(project(":core:metadata.jvm"))
api(project(":core:deserialization.common")) api(project(":core:deserialization.common"))
implementation(project(":core:compiler.common.jvm")) implementation(project(":core:compiler.common.jvm"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
@@ -8,6 +8,7 @@ project.configureJvmToolchain(JdkMajorVersion.JDK_1_6)
dependencies { dependencies {
api(project(":core:compiler.common")) api(project(":core:compiler.common"))
api(project(":core:metadata")) api(project(":core:metadata"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -11,6 +11,7 @@ dependencies {
api(project(":core:util.runtime")) api(project(":core:util.runtime"))
api(project(":core:descriptors")) api(project(":core:descriptors"))
api(commonDependency("javax.inject")) api(commonDependency("javax.inject"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -7,6 +7,7 @@ project.configureJvmToolchain(JdkMajorVersion.JDK_1_6)
dependencies { dependencies {
api(project(":core:metadata")) api(project(":core:metadata"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -8,6 +8,7 @@ project.configureJvmToolchain(JdkMajorVersion.JDK_1_6)
dependencies { dependencies {
api(protobufLite()) api(protobufLite())
api(kotlinStdlib()) api(kotlinStdlib())
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -7,6 +7,7 @@ project.configureJvmToolchain(JdkMajorVersion.JDK_1_6)
dependencies { dependencies {
compileOnly(kotlinStdlib()) compileOnly(kotlinStdlib())
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
@@ -7,6 +7,7 @@ JvmToolchain.updateJvmTarget(project, "1.6")
dependencies { dependencies {
api kotlinStdlib("common") api kotlinStdlib("common")
testApi project(":kotlin-test:kotlin-test-common") testApi project(":kotlin-test:kotlin-test-common")
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile) { tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile) {
@@ -18,4 +19,4 @@ jar {
} }
configureSourcesJar() configureSourcesJar()
configureJavadocJar() configureJavadocJar()
@@ -7,6 +7,7 @@ JvmToolchain.updateJvmTarget(project, "1.6")
dependencies { dependencies {
api kotlinStdlib("common") api kotlinStdlib("common")
testApi project(":kotlin-test:kotlin-test-annotations-common") testApi project(":kotlin-test:kotlin-test-annotations-common")
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
jar { jar {
+1
View File
@@ -16,6 +16,7 @@ dependencies {
expectedBy project(':kotlin-test:kotlin-test-annotations-common') expectedBy project(':kotlin-test:kotlin-test-annotations-common')
api project(':kotlin-test:kotlin-test-jvm') api project(':kotlin-test:kotlin-test-jvm')
api('junit:junit:4.13.2') api('junit:junit:4.13.2')
kotlinCompilerClasspath(project(':libraries:tools:stdlib-compiler-classpath'))
} }
+1
View File
@@ -19,6 +19,7 @@ dependencies {
api(kotlinStdlib()) api(kotlinStdlib())
testApi(project(":kotlin-test:kotlin-test-junit")) testApi(project(":kotlin-test:kotlin-test-junit"))
testApi('junit:junit:4.13.2') testApi('junit:junit:4.13.2')
kotlinCompilerClasspath(project(':libraries:tools:stdlib-compiler-classpath'))
} }
jar { jar {
@@ -20,6 +20,7 @@ dependencies {
if (includeJava9) { if (includeJava9) {
java9CompileOnly('org.testng:testng:7.0.0') java9CompileOnly('org.testng:testng:7.0.0')
} }
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
jar { jar {
+1
View File
@@ -29,6 +29,7 @@ dependencies {
compileOnly project(':core:descriptors.runtime') compileOnly project(':core:descriptors.runtime')
compileOnly project(':core:util.runtime') compileOnly project(':core:util.runtime')
compileOnly "org.jetbrains:annotations:13.0" compileOnly "org.jetbrains:annotations:13.0"
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
if (includeJava9) { if (includeJava9) {
@@ -9,6 +9,7 @@ dependencies {
api(kotlinStdlib()) api(kotlinStdlib())
compileOnly(project(":kotlin-reflect-api")) compileOnly(project(":kotlin-reflect-api"))
testApi(commonDependency("junit")) testApi(commonDependency("junit"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
@@ -34,6 +34,7 @@ dependencies {
testRuntimeOnly("org.slf4j:slf4j-nop:1.7.30") testRuntimeOnly("org.slf4j:slf4j-nop:1.7.30")
testImplementation(kotlin("reflect")) testImplementation(kotlin("reflect"))
testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
@@ -10,6 +10,7 @@ dependencies {
api(project(":kotlin-scripting-common")) api(project(":kotlin-scripting-common"))
testApi(commonDependency("junit")) testApi(commonDependency("junit"))
testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -10,6 +10,7 @@ dependencies {
api(kotlinStdlib()) api(kotlinStdlib())
api(project(":kotlin-scripting-common")) api(project(":kotlin-scripting-common"))
testApi(commonDependency("junit")) testApi(commonDependency("junit"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+1
View File
@@ -44,6 +44,7 @@ configurations {
dependencies { dependencies {
api project(':kotlin-stdlib') api project(':kotlin-stdlib')
testApi project(':kotlin-test:kotlin-test-junit') testApi project(':kotlin-test:kotlin-test-junit')
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
jar { jar {
@@ -20,6 +20,7 @@ val builtins by configurations.creating {
dependencies { dependencies {
compileOnly(project(":kotlin-stdlib")) compileOnly(project(":kotlin-stdlib"))
builtins(project(":core:builtins")) builtins(project(":core:builtins"))
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
} }
sourceSets { sourceSets {
+2
View File
@@ -63,6 +63,8 @@ dependencies {
testApi project(':kotlin-test:kotlin-test-junit') testApi project(':kotlin-test:kotlin-test-junit')
builtins project(':core:builtins') builtins project(':core:builtins')
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
jar { jar {
@@ -16,6 +16,7 @@ sourceSets {
dependencies { dependencies {
compileOnly DependenciesKt.kotlinBuiltins(project) compileOnly DependenciesKt.kotlinBuiltins(project)
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
configureSourcesJar() configureSourcesJar()
@@ -24,4 +24,4 @@ interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToo
* Default value: false * Default value: false
*/ */
var useFir: kotlin.Boolean var useFir: kotlin.Boolean
} }
@@ -12,8 +12,8 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption
var javaParameters: kotlin.Boolean var javaParameters: kotlin.Boolean
/** /**
* Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, ..., 18), default is 1.8 * Target version of the generated JVM bytecode (1.8, 9, 10, ..., 18), default is 1.8
* Possible values: "1.6", "1.8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18" * Possible values: "1.8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"
* Default value: null * Default value: null
*/ */
var jvmTarget: kotlin.String? var jvmTarget: kotlin.String?
@@ -8,6 +8,7 @@ configurePublishing(project)
dependencies { dependencies {
compileOnly kotlinStdlib() compileOnly kotlinStdlib()
kotlinCompilerClasspath project(':libraries:tools:stdlib-compiler-classpath')
} }
sourceSets { sourceSets {
@@ -0,0 +1,9 @@
plugins {
java
id("jps-compatible")
}
sourceSets {
"main" { projectDefault() }
"test" {}
}
+2 -1
View File
@@ -313,7 +313,8 @@ include ":benchmarks",
":kotlinx-serialization-compiler-plugin", ":kotlinx-serialization-compiler-plugin",
":kotlin-serialization", ":kotlin-serialization",
":kotlin-serialization-unshaded", ":kotlin-serialization-unshaded",
":wasm:wasm.ir" ":wasm:wasm.ir",
":libraries:tools:stdlib-compiler-classpath"
include ":kotlinx-atomicfu-compiler-plugin", include ":kotlinx-atomicfu-compiler-plugin",