Mark obsolete Gradle JVM options as Deprecated with Error
Options `includeRuntime`, `noStdlib` and `noReflect` were affected #Fixed KT-44361
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.cli.common.arguments
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class DeprecatedOption(
|
||||||
|
val message: String = "This option has no effect and will be removed in a future release.",
|
||||||
|
val removeAfter: String,
|
||||||
|
val level: DeprecationLevel
|
||||||
|
)
|
||||||
+3
@@ -25,6 +25,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
|||||||
description = "List of directories and JAR/ZIP archives to search for user class files")
|
description = "List of directories and JAR/ZIP archives to search for user class files")
|
||||||
var classpath: String? by NullableStringFreezableVar(null)
|
var classpath: String? by NullableStringFreezableVar(null)
|
||||||
|
|
||||||
|
@DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR)
|
||||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||||
@Argument(value = "-include-runtime", description = "Include Kotlin runtime into the resulting JAR")
|
@Argument(value = "-include-runtime", description = "Include Kotlin runtime into the resulting JAR")
|
||||||
var includeRuntime: Boolean by FreezableVar(false)
|
var includeRuntime: Boolean by FreezableVar(false)
|
||||||
@@ -41,10 +42,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(value = "-no-jdk", description = "Don't automatically include the Java runtime into the classpath")
|
@Argument(value = "-no-jdk", description = "Don't automatically include the Java runtime into the classpath")
|
||||||
var noJdk: Boolean by FreezableVar(false)
|
var noJdk: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
@DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR)
|
||||||
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
||||||
@Argument(value = "-no-stdlib", description = "Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath")
|
@Argument(value = "-no-stdlib", description = "Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath")
|
||||||
var noStdlib: Boolean by FreezableVar(false)
|
var noStdlib: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
@DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR)
|
||||||
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
||||||
@Argument(value = "-no-reflect", description = "Don't automatically include Kotlin reflection into the classpath")
|
@Argument(value = "-no-reflect", description = "Don't automatically include Kotlin reflection into the classpath")
|
||||||
var noReflect: Boolean by FreezableVar(false)
|
var noReflect: Boolean by FreezableVar(false)
|
||||||
|
|||||||
+28
-2
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.generators.arguments
|
package org.jetbrains.kotlin.generators.arguments
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersion
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -159,8 +160,15 @@ fun main() {
|
|||||||
generateKotlinGradleOptions(::getPrinter)
|
generateKotlinGradleOptions(::getPrinter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline fun <reified T : Any> List<KProperty1<T, *>>.filterToBeDeleted() = filter { prop ->
|
||||||
|
prop.findAnnotation<DeprecatedOption>()
|
||||||
|
?.let { LanguageVersion.fromVersionString(it.removeAfter) }
|
||||||
|
?.let { it >= LanguageVersion.LATEST_STABLE }
|
||||||
|
?: true
|
||||||
|
}
|
||||||
|
|
||||||
private inline fun <reified T : Any> gradleOptions(): List<KProperty1<T, *>> =
|
private inline fun <reified T : Any> gradleOptions(): List<KProperty1<T, *>> =
|
||||||
T::class.declaredMemberProperties.filter { it.findAnnotation<GradleOption>() != null }.sortedBy { it.name }
|
T::class.declaredMemberProperties.filter { it.findAnnotation<GradleOption>() != null }.filterToBeDeleted().sortedBy { it.name }
|
||||||
|
|
||||||
private fun File(baseDir: File, fqName: FqName): File {
|
private fun File(baseDir: File, fqName: FqName): File {
|
||||||
val fileRelativePath = fqName.asString().replace(".", "/") + ".kt"
|
val fileRelativePath = fqName.asString().replace(".", "/") + ".kt"
|
||||||
@@ -173,6 +181,7 @@ private fun Printer.generateInterface(type: FqName, properties: List<KProperty1<
|
|||||||
for (property in properties) {
|
for (property in properties) {
|
||||||
println()
|
println()
|
||||||
generateDoc(property)
|
generateDoc(property)
|
||||||
|
generateOptionDeprecation(property)
|
||||||
generatePropertyDeclaration(property)
|
generatePropertyDeclaration(property)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,6 +257,12 @@ private fun Printer.generatePropertyDeclaration(property: KProperty1<*, *>, modi
|
|||||||
println("$modifiers var ${property.name}: $returnType")
|
println("$modifiers var ${property.name}: $returnType")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Printer.generateOptionDeprecation(property: KProperty1<*, *>) {
|
||||||
|
property.findAnnotation<DeprecatedOption>()
|
||||||
|
?.let { DeprecatedOptionAnnotator.generateOptionAnnotation(it) }
|
||||||
|
?.also { println(it) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun Printer.generateDoc(property: KProperty1<*, *>) {
|
private fun Printer.generateDoc(property: KProperty1<*, *>) {
|
||||||
val description = property.findAnnotation<Argument>()!!.description
|
val description = property.findAnnotation<Argument>()!!.description
|
||||||
val possibleValues = property.gradleValues.possibleValues
|
val possibleValues = property.gradleValues.possibleValues
|
||||||
@@ -274,6 +289,8 @@ private fun generateMarkdown(properties: List<KProperty1<*, *>>) {
|
|||||||
for (property in properties) {
|
for (property in properties) {
|
||||||
val name = property.name
|
val name = property.name
|
||||||
if (name == "includeRuntime") continue // This option has no effect in Gradle builds
|
if (name == "includeRuntime") continue // This option has no effect in Gradle builds
|
||||||
|
val renderName = listOfNotNull("`$name`", property.findAnnotation<DeprecatedOption>()?.let { "__(Deprecated)__" })
|
||||||
|
.joinToString(" ")
|
||||||
val description = property.findAnnotation<Argument>()!!.description
|
val description = property.findAnnotation<Argument>()!!.description
|
||||||
val possibleValues = property.gradleValues.possibleValues
|
val possibleValues = property.gradleValues.possibleValues
|
||||||
val defaultValue = when (property.gradleDefaultValue) {
|
val defaultValue = when (property.gradleDefaultValue) {
|
||||||
@@ -282,7 +299,7 @@ private fun generateMarkdown(properties: List<KProperty1<*, *>>) {
|
|||||||
else -> property.gradleDefaultValue
|
else -> property.gradleDefaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
println("| `$name` | $description | ${possibleValues.orEmpty().joinToString()} | $defaultValue |")
|
println("| $renderName | $description | ${possibleValues.orEmpty().joinToString()} | $defaultValue |")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,3 +321,12 @@ private val KProperty1<*, *>.gradleReturnType: String
|
|||||||
|
|
||||||
private inline fun <reified T> KAnnotatedElement.findAnnotation(): T? =
|
private inline fun <reified T> KAnnotatedElement.findAnnotation(): T? =
|
||||||
annotations.filterIsInstance<T>().firstOrNull()
|
annotations.filterIsInstance<T>().firstOrNull()
|
||||||
|
|
||||||
|
object DeprecatedOptionAnnotator {
|
||||||
|
fun generateOptionAnnotation(annotation: DeprecatedOption): String {
|
||||||
|
val message = annotation.message.takeIf { it.isNotEmpty() }?.let { "message = \"$it\"" }
|
||||||
|
val level = "level = DeprecationLevel.${annotation.level.name}"
|
||||||
|
val arguments = listOfNotNull(message, level).joinToString()
|
||||||
|
return "@Deprecated($arguments)"
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -8,6 +8,7 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption
|
|||||||
* Include Kotlin runtime into the resulting JAR
|
* Include Kotlin runtime into the resulting JAR
|
||||||
* Default value: false
|
* Default value: false
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(message = "This option has no effect and will be removed in a future release.", level = DeprecationLevel.ERROR)
|
||||||
var includeRuntime: kotlin.Boolean
|
var includeRuntime: kotlin.Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,12 +46,14 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption
|
|||||||
* Don't automatically include Kotlin reflection into the classpath
|
* Don't automatically include Kotlin reflection into the classpath
|
||||||
* Default value: true
|
* Default value: true
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(message = "This option has no effect and will be removed in a future release.", level = DeprecationLevel.ERROR)
|
||||||
var noReflect: kotlin.Boolean
|
var noReflect: kotlin.Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath
|
* Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath
|
||||||
* Default value: true
|
* Default value: true
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(message = "This option has no effect and will be removed in a future release.", level = DeprecationLevel.ERROR)
|
||||||
var noStdlib: kotlin.Boolean
|
var noStdlib: kotlin.Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user