如何替换 java-library 和 kotlin 模块中已弃用的 kotlinOptions?

问题描述 投票:0回答:1

在我的 Android 应用程序项目中,我使用以下 Gradle (Groovy) 配置作为库模块:

// 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 通知我

kotlinOptions
已弃用

没有可以应用的快速解决方案。如何正确替换符号?这种库模块似乎有不同的语法。

com.android.library
模块和
com.android.application
模块中都没有弃用警告。两者都使用
kotlin-android
插件(如果这是一个重要的区别)。

潜在答案

...将它们视为非官方弃用...

来源:https://youtrack.jetbrains.com/issue/KT-27301/Expose-compiler-flags-via-Gradle-lazy-properties#focus=Comments-27-6565858.0-0

相关

android kotlin groovy deprecated java-module
1个回答
0
投票

编译任务具有新的

compilerOptions
输入,该输入与现有
kotlinOptions
类似,但使用 Gradle Properties API 中的
Property
作为返回类型。

这是您的更新代码:

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")
  }
}

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.