How to set freeCompilerArgs for common files

According to this documentation I can add the compiler arg -Xopt-in=kotlin.time.ExperimentalTime and I don’t have to add the annotation all over my code.

I have a multiplatform project with js and jvm, and I’m still getting this error.

e: DataTransferTypes.kt: (54, 24): This declaration is experimental and its
usage must be marked with '@kotlin.time.ExperimentalTime' or 
@OptIn(kotlin.time.ExperimentalTime::class)'

Despite the following in my gradle file. How do I pass that arg to the compile for common classes?

jvm {
    compilations.all {
        kotlinOptions {
            …
            freeCompilerArgs += listOf(
                "-Xopt-in=kotlin.time.ExperimentalTime", …
            )
        }
    }
    …
}
js(IR) {
    …
    compilations.all {
        kotlinOptions {
            freeCompilerArgs += listOf(
                "-Xopt-in=kotlin.time.ExperimentalTime", …
            )
        }
    }
}

You can use the following API to opt-in for experimental annotations in a multiplatform projects:

kotlin {
    sourceSets.all {
        languageSettings.apply {
            useExperimentalAnnotation("kotlin.time.ExperimentalTime")
        }
    }
}
1 Like

Note, since Kotlin 1.7.0 this has been renamed to optIn().

sourceSets {
    all {
        languageSettings.optIn("org.mylibrary.OptInAnnotation")
    }
}
1 Like