Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 696
Michael restore Monica Cellio Avatar asked Dec 14 '18 22:12

Michael restore Monica Cellio


People also ask

How do I use optin Kotlin?

To opt in to using an API in a module, compile it with the argument -opt-in , specifying the fully qualified name of the opt-in requirement annotation of the API you use: -opt-in=org. mylibrary.


2 Answers

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"] } 
like image 139
Jay Yanez Avatar answered Sep 22 '22 01:09

Jay Yanez


In the current Kotlin version (1.5), you can use any experimental library by adding @OptIn annotation

@OptIn(ExperimentalCoroutinesApi::class) 

However, the opt-in mechanism is experimental itself, and to use it you will need to add a compiler argument. The most idiomatic way to do that in Kotlin Multiplatform is:

kotlin.sourceSets.all {     languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn") } 
like image 28
Max Cruz Avatar answered Sep 20 '22 01:09

Max Cruz