Reports usages of the deprecated kotlinOptions DSL in Gradle .kts build scripts.

The kotlinOptions DSL was deprecated in Kotlin 2.0. The inspection helps migrate from kotlinOptions to compilerOptions. It also changes the types of several options that use the new types instead of the String type.

Example for the KotlinCompile task:


val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
    jvmTarget = "1.8"
    freeCompilerArgs = listOf("-module-name", "my_module_name")
    apiVersion = "1.9"
}

//OR

tasks.withType {
    kotlinOptions {
        freeCompilerArgs += listOf("-module-name", "my_module_name")
    }
}

The inspection also adds imports for options with changed types:


import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

...

val compileKotlin: KotlinCompile by tasks
compileKotlin.compilerOptions {
    jvmTarget.set(JvmTarget.JVM_1_8)
    freeCompilerArgs.set(listOf("-module-name", "my_module_name"))
    apiVersion.set(KotlinVersion.KOTLIN_1_9)
}

Example for the Kotlin2JsCompile task:


val compileKotlin: Kotlin2JsCompile by tasks
compileKotlin.kotlinOptions {
    moduleKind = "commonjs"
    sourceMapEmbedSources = "inlining"
    sourceMapNamesPolicy = "fully-qualified-names"
    main = "noCall"
}

After the inspection is applied:


import org.jetbrains.kotlin.gradle.dsl.JsMainFunctionExecutionMode
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapNamesPolicy

...

val compileKotlin: Kotlin2JsCompile by tasks
compileKotlin.compilerOptions {
    moduleKind.set(JsModuleKind.MODULE_COMMONJS)
    sourceMapEmbedSources.set(JsSourceMapEmbedMode.SOURCE_MAP_SOURCE_CONTENT_INLINING)
    sourceMapNamesPolicy.set(JsSourceMapNamesPolicy.SOURCE_MAP_NAMES_POLICY_FQ_NAMES)
    main.set(JsMainFunctionExecutionMode.NO_CALL)
}