Opt-in for experimental Kotlin API's in gradle files

  • #  android
  • #  kotlin
  • #  gradle
  • In an Android module

    plugins {
        id "com.android.library"
        id "kotlin-android"
    }
    
    android {
        defaultConfig {
            kotlinOptions {
                freeCompilerArgs += [
                    "-opt-in=kotlin.time.ExperimentalTime",
                    "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
                ]
            }
        }
    }
    

    In a Kotlin module

    plugins {
        id "org.jetbrains.kotlin.jvm"
    }
    
    compileKotlin {
        kotlinOptions {
            freeCompilerArgs += [
                "-opt-in=kotlin.time.ExperimentalTime",
                "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
            ]
        }
    }
    

    In all Kotlin modules

    Add the following snippet to the root gradle.build file:

    allprojects {
        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
            kotlinOptions {
                jvmTarget = "1.8"
                freeCompilerArgs += [
                    "-opt-in=kotlin.time.ExperimentalTime",
                    "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
                ]
            }
        }
    }