The `use-experimental` compiler argument either do...
# announcements
e
The
use-experimental
compiler argument either does not work as advertised (has a bug) or is not configured properly. Whats the correct way to configure the
use-experimental
compiler argument with gradle (kotlin dsl) such that I do not get warnings for using experimental APIs in my code? Right now I have this
Copy code
subprojects {

  // ... 

  project.tasks.withType<KotlinCompile> {
    kotlinOptions {
      freeCompilerArgs = listOf(
        "-Xuse-experimental=kotlin.Experimental,kotlinx.coroutines.ExperimentalCoroutinesApi,kotlinx.serialization.ImplicitReflectionSerializer"
      )
    }
  }
}
in my root build gradle file but I still get warnings like in the attached image (both
Flow
and
fun dispatcher.invoke( ... )
are experimental APIs)
n
#gradle?
e
Will x-post
Also switched to
Copy code
project.tasks.withType<KotlinCompile> {
    kotlinOptions {
      freeCompilerArgs = listOf(
        "-Xuse-experimental=kotlin.Experimental",
        "-Xuse-experimental=kotlinx.serialization.ImplicitReflectionSerializer",
        "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
        "-Xuse-experimental=kotlinx.coroutines.FlowPreview"
      )
    }
  }
…no dice.
i
Have you refreshed project from Gradle after these changes?
e
Yes.
@ilya.gorbunov Which is the more correct definition, iniitial message (specify comma separated multiple fqcn) or the last one (specify multiple flags each with one fqcn)
i
Both should be fine. Can you check which arguments are shown in the Kotlin facet of your module in the project structure?
e
Ah I forgot to add, I am using AS 3.6 canary and gradle kotlin dsl so extra information does not show up in project structure.
i
Could it be that a specific KotlinCompile task overrides
freeCompilerArgs
with another list?
Do you get these experimental warnings in IDE only or during gradle build too?
e
I dont think so. I define the
freeCompilerArgs
in one location only; within
subprojects
block of the root build file. I have also tried wrapping in
project.afterEvaluate { ... }
with no luck
Err both iirc. Lemme run a gradle build to confirm. @ilya.gorbunov confirmed, warning is only in IDE.
i
Then it's most likely related to importing these options into IDE, but it's hard to tell at this point what is wrong. Could you file an issue with details (and better with the build scripts to reproduce the problem) here https://kotl.in/issue?
e
Also confirmed, both syntaxes work for gradle build but IDE has warnings.
Alright, I’ll do that when I get home. Thanks @ilya.gorbunov