How to suppress specific Kotlinc/Javac compiler warnings?

自闭症网瘾萝莉.ら 提交于 2020-05-07 21:23:51

问题


How to suppress deprecations in for KotlinCompile in Gradle similar to JavaCompile?

JavaCompile(works):

tasks.withType(JavaCompile) {
    configure(options) {
        compilerArgs << '-Xlint:-deprecation'
    }
}

KotlinCompile(does not work):

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        freeCompilerArgs = ["-Xjavac-arguments=-Xlint:-deprecation"]
    }
}

References:

  • https://kotlinlang.org/docs/reference/using-gradle.html#compiler-options

Similar questions:

  • kotlin supress warning deprecated for android
  • Mark unused parameters in Kotlin
  • Kotlin: Suppress unused Property?
  • How do I make the Kotlin compiler treat warnings as errors?

回答1:


It looks like there is a suppressWarnings option on the kotlinOptions property defined on the KotlinCompile task. Setting that to true may do what you want.

This is how you would do that:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        suppressWarnings = true
    }
}


来源:https://stackoverflow.com/questions/52488930/how-to-suppress-specific-kotlinc-javac-compiler-warnings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!