问题
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