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:
+1
-1
@@ -37,7 +37,7 @@ open class DefaultValues(val defaultValue: String, val possibleValues: List<Stri
|
||||
|
||||
object JvmTargetVersions : DefaultValues(
|
||||
"null",
|
||||
JvmTarget.values().map { "\"${it.description}\"" }
|
||||
JvmTarget.supportedValues().map { "\"${it.description}\"" }
|
||||
)
|
||||
|
||||
object JsEcmaVersions : DefaultValues(
|
||||
|
||||
+3
-2
@@ -75,7 +75,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(
|
||||
value = "-jvm-target",
|
||||
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)
|
||||
|
||||
@@ -466,7 +466,8 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
|
||||
|
||||
@Argument(
|
||||
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)
|
||||
|
||||
|
||||
@@ -56,10 +56,10 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
||||
val jvmTarget = JvmTarget.fromString(jvmTargetValue)
|
||||
if (jvmTarget != null) {
|
||||
put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
|
||||
if (jvmTarget == JvmTarget.JVM_1_6 && !arguments.suppressDeprecatedJvmTargetWarning) {
|
||||
if (jvmTarget == JvmTarget.JVM_1_6 && !isJvmTarget6Allowed()) {
|
||||
messageCollector.report(
|
||||
STRONG_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"
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -353,3 +353,6 @@ private val CompilerConfiguration.messageCollector: MessageCollector
|
||||
|
||||
private fun getJavaVersion(): Int =
|
||||
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"
|
||||
else "JVM bytecode version $majorVersion"
|
||||
}
|
||||
|
||||
fun supportedValues(): List<JvmTarget> =
|
||||
values().asList() - JVM_1_6
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -131,7 +131,8 @@ where advanced options include:
|
||||
Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl).
|
||||
Default value is 'enable'
|
||||
-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
|
||||
Suppress the "cannot access built-in declaration" error (useful with -no-stdlib)
|
||||
-Xtype-enhancement-improvements-strict-mode
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ where possible options include:
|
||||
-include-runtime Include Kotlin runtime into the resulting JAR
|
||||
-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
|
||||
-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
|
||||
-no-jdk Don't automatically include the Java runtime into the classpath
|
||||
-no-reflect Don't automatically include Kotlin reflection into the classpath
|
||||
|
||||
+2
-2
@@ -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
|
||||
OK
|
||||
error: JVM target 1.6 is no longer supported. Please migrate to JVM target 1.8 or above
|
||||
COMPILATION_ERROR
|
||||
|
||||
+1
-1
@@ -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'
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -8,6 +8,7 @@ project.updateJvmTarget("1.6")
|
||||
dependencies {
|
||||
api(kotlinStdlib())
|
||||
testApi(project(":kotlin-test:kotlin-test-jvm"))
|
||||
kotlinCompilerClasspath(project(":libraries:tools:stdlib-compiler-classpath"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
Reference in New Issue
Block a user