Deprecate JVM target 1.6
#KT-44650 Fixed
This commit is contained in:
+7
-1
@@ -71,7 +71,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(
|
||||
value = "-jvm-target",
|
||||
valueDescription = "<version>",
|
||||
description = "Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8"
|
||||
description = "Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8"
|
||||
)
|
||||
var jvmTarget: String? by NullableStringFreezableVar(JvmTarget.DEFAULT.description)
|
||||
|
||||
@@ -448,6 +448,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var enableJvmPreview: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xsuppress-deprecated-jvm-target-warning",
|
||||
description = "Suppress deprecation warning about deprecated JVM target versions"
|
||||
)
|
||||
var suppressDeprecatedJvmTargetWarning: Boolean by FreezableVar(false)
|
||||
|
||||
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
|
||||
val result = super.configureAnalysisFlags(collector)
|
||||
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
||||
|
||||
@@ -29,6 +29,12 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
||||
val jvmTarget = JvmTarget.fromString(arguments.jvmTarget!!)
|
||||
if (jvmTarget != null) {
|
||||
put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
|
||||
if (jvmTarget == JvmTarget.JVM_1_6 && !arguments.suppressDeprecatedJvmTargetWarning) {
|
||||
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"
|
||||
)
|
||||
}
|
||||
} else {
|
||||
messageCollector.report(
|
||||
ERROR, "Unknown JVM target version: ${arguments.jvmTarget}\n" +
|
||||
|
||||
+2
@@ -118,6 +118,8 @@ where advanced options include:
|
||||
-Xsupport-compatqual-checker-framework-annotations=enable|disable
|
||||
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
|
||||
-Xsuppress-missing-builtins-error
|
||||
Suppress the "cannot access built-in declaration" error (useful with -no-stdlib)
|
||||
-Xuse-ir Use the IR backend
|
||||
|
||||
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, 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8
|
||||
-jvm-target <version> Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, 11, 12, 13, 14 or 15), 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
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/jvm8Target.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-jvm-target
|
||||
1.6
|
||||
+2
@@ -0,0 +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
|
||||
+1
@@ -1,2 +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: '-Xjvm-default=all' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8'
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -536,6 +536,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
runTest("compiler/testData/cli/jvm/jsr305Warn.args");
|
||||
}
|
||||
|
||||
@TestMetadata("jvm6Target.args")
|
||||
public void testJvm6Target() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/jvm6Target.args");
|
||||
}
|
||||
|
||||
@TestMetadata("jvm8Target.args")
|
||||
public void testJvm8Target() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/jvm8Target.args");
|
||||
|
||||
+9
-5
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.codegen.inline.remove
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.asSequence
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.intConstant
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion.TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
@@ -43,6 +44,7 @@ import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.valid
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.ClassNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
import java.io.ByteArrayInputStream
|
||||
@@ -609,11 +611,13 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
|
||||
}
|
||||
|
||||
fun testInlineAnonymousObjectWithDifferentTarget() {
|
||||
val library = compileLibrary("library", additionalOptions = listOf("-jvm-target", "1.6"))
|
||||
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-jvm-target", "1.8"))
|
||||
val classLoader =
|
||||
URLClassLoader(arrayOf(library.toURI().toURL(), tmpdir.toURI().toURL()), ForTestCompileRuntime.runtimeJarClassLoader())
|
||||
classLoader.loadClass("SourceKt").getDeclaredMethod("main").invoke(null)
|
||||
val library = compileLibrary("library", additionalOptions = listOf("-jvm-target", JvmTarget.JVM_1_8.description))
|
||||
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-jvm-target", JvmTarget.JVM_9.description))
|
||||
for (name in listOf("SourceKt", "SourceKt\$main\$\$inlined\$foo$1")) {
|
||||
val node = ClassNode()
|
||||
ClassReader(File(tmpdir, "$name.class").readBytes()).accept(node, 0)
|
||||
assertEquals(JvmTarget.JVM_9.majorVersion, node.version)
|
||||
}
|
||||
}
|
||||
|
||||
fun testFirAgainstFir() {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption
|
||||
var jdkHome: kotlin.String?
|
||||
|
||||
/**
|
||||
* Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8
|
||||
* Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8
|
||||
* Possible values: "1.6", "1.8", "9", "10", "11", "12", "13", "14", "15"
|
||||
* Default value: "1.8"
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user