How to set '-Xuse-experimental=kotlin.experimental' in IntelliJ

时光怂恿深爱的人放手 提交于 2020-12-04 15:58:07

问题


while trying to build a Kotlin/Ktor application in IntelliJ, multiple warnings of the form

Warning:(276, 6) Kotlin: This class can only be used with the compiler argument '-Xuse-experimental=kotlin.Experimental'

are output. The warnings refer to

@UseExperimental(KtorExperimentalLocationsAPI::class)

so I expected to satisfy the warning by setting Settings -> Build -> Compiler -> Kotlin Compiler -> Additional command line parameters to -version -Xuse-experimental=kotlin.Experimental. (-version was already there). But the warning is still generated. How do I satisfy it? Thanks in expectation.


回答1:


Are you using Maven or Gradle for your project? I had the same issue with Gradle, but I was able to remove the warnings by putting the -Xuse-experimental=kotlin.Experimental in my build.gradle file, inside a tasks.withType.

For KtorExperimentalLocationsAPI you could try:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=io.ktor.locations.KtorExperimentalLocationsAPI"]
}



回答2:


Edit for Graddle 6.5.1 and Ktor 1.3.2. Answer by @jay-janez looks like that:

tasks.withType(KotlinCompile::class).all {
    kotlinOptions.freeCompilerArgs += "-Xuse-experimental=io.ktor.util.KtorExperimentalAPI"
}


来源:https://stackoverflow.com/questions/53787542/how-to-set-xuse-experimental-kotlin-experimental-in-intellij

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