my build.gradle file contains the folowing section: ```compileKotlin { kotlinOptions { j...
ł
my build.gradle file contains the folowing section:
Copy code
compileKotlin {
    kotlinOptions {
        jvmTarget = "14"
        allWarningsAsErrors = true
        freeCompilerArgs += [

                "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
                "-Xopt-in=kotlin.RequiresOptIn",
                "-Xopt-in=kotlinx.coroutines.ObsoleteCoroutinesApi"]
    }
}
However since kotlin 1.6.0 the -Xopt-in flag shoud be replaced with -opt-in. The problem is that I often switch kotlin version (and then I remove/add the X character). Is there a way to have one gradle file that works for both kotlin 1.5 and kotlin 1.6?
v
Add an
if
to do the right thing for the current kotlin version?
t
There is a non-official method to get current Kotlin Plugin version - you could use it
e
use languageSettings instead
works the same on every version
ł
Copy code
sourceSets.main {
languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
}
No signature of method: org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder.optIn() is applicable for argument types: (String) values: [kotlinx.coroutines.ExperimentalCoroutinesApi]
v
You miss the
kotlin.
I guess
ł
I've tried kotlin. as well. Still the same error.
e
try
Copy code
kotlin.target.compilations.named("main") {
    languageSettings {
        optIn("...")
        optIn("...")
    }
}
in a JVM-only project
ł
optIn option has been added in kotlin gradle plugin 1.5.30, I'm using 1.5.20, that is why I can't see it
I'm wondering if it is possible/recommended to use kotlin 1.5.20 but kotlin gradle plugin 1.5.30
e
use langaugeSettings.optIn instead of freeCompilerArgs. the plugin will do the right thing for that version.
c
revc..
⁉️ 1
oops 🙂