Within my Android application project I am using the following Gradle (Groovy) configuration for a library module:
// build.gradle
apply plugin: "java-library"
apply plugin: "kotlin"
dependencies {
api Libs.engelsystem
implementation(Libs.retrofit) {
exclude group: "com.squareup.okio", module: "okio"
}
testImplementation Libs.junit
testImplementation Libs.kotlinCoroutinesTest
testImplementation Libs.mockitoKotlin
testImplementation Libs.okhttpMockWebServer
testImplementation Libs.retrofitConverterMoshi
testImplementation Libs.truth
}
sourceCompatibility = Config.compatibleJavaVersion
targetCompatibility = Config.compatibleJavaVersion
compileKotlin {
kotlinOptions {
jvmTarget = Config.compatibleJavaVersion // is set to JavaVersion.VERSION_11
freeCompilerArgs += [
"-opt-in=kotlin.RequiresOptIn"
]
}
}
Android Studio Giraffe / Lint notifies me that kotlinOptions
is deprecated.
There is no quick fix to apply. How can I replace the notation correctly? It seems there is a different syntax for this kind of library module. There is no deprecation warning in a com.android.library
module nor in a com.android.application
module. Both use the kotlin-android
plugin if that is an important difference.
... consider them as non-officially deprecated ...
Compile tasks have the new compilerOptions
input, which is similar to the existing kotlinOptions
but uses Property from the Gradle
Properties API as the return type.
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
tasks.withType(KotlinJvmCompile).configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
}
}
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
}
}
References: