How to use Kotlin Experimental Time project wide?

Viewed 1499

Is it possible to avoid the need to annotate every part of my code with @ExperimentalTime? After looking around I tried this in my gradle build:

withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
    kotlinOptions.freeCompilerArgs += "-Xuse-experimental=kotlin.time.ExperimentalTime"
}

But trying to build the project still stops with an error that I have usages that need the annotation.

2 Answers

This is an issue with the Experimental Tag in Kotlin, it is possible to have the OptIn annotation accessible, and then to use that instead of Experimental, as the OptIn does not propagate from the base usage, but this only works if you don't have to use the ExperimentalTime all over the module. Specifically the top block of this link: Opt-In

This should work:

freeCompilerArgs += "-opt-in=kotlin.time.ExperimentalTime"
Related