Is there a way to only allow experimental coroutin...
# coroutines
Is there a way to only allow experimental coroutines for tests? My gradle-fu is not exemplary.
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.Experimental"]
You mean experimental coroutines api? You need to filter the tasks that compile tests. The Gradle tool window in the IDE might be helpful. Also, note that you're activating the Experimental feature of Kotlin in this snippet, not ExperimentalCoroutinesApi.
👍 1
so the warning I’m seeing is
This declaration is experimental and its usages should be marked with @ExperimentalCoroutinesApi or @UseExperimental(ExperimentalCoroutinesApi::class)
so I marked the class with the @UseExperimental annotation but then it warns me
This class can only be used with the compiler argument -Xuse-experimental=kotlin.Experimental
. Does that differ from what you just said? I’m also unsure on what operators to use to filter on test tasks only.
You can use their name to filter the ones for tests.
is experimental, so you need to opt-in to
, but an alternative is to opt-in to
and not need to add
annotation to its usages. I tend to use
so I know exactly where they are in case I want or need to change them while them not being deprecated, but I could as well opt-in for all.
using kotlinOptions is the recommemded one. As stated above, because when you annotating the
you'll refactor your code to the outside layer as well (the code that implemented it) and it's ugly imho
And for your question, maybe you can wrap the
inside the if condition if the source directory is under
. But that would be my suggestion, I didn't tried that one as well. *nice question