Hi. how can I opt-in for all annotations? tried so...
# multiplatform
g
Hi. how can I opt-in for all annotations? tried something like
all { languageSettings.optIn("*") }
but it does not work
fails with
Copy code
e: file:///Users/Giorgi_Shalvashvili/IdeaProjects/catchclicker/data/src/commonTest/kotlin/com/app/data/bluetooth/dto/SetupPacketTest.kt:40:25 This declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
m
I'm not sure if there is a way not need to use it all, but you can add this in
build.gradle.kts
Copy code
kotlin {
    targets.all {
        compilations.all {
            compileTaskProvider.configure {
                compilerOptions {
                    // For the usage of expect/actual warning
                    freeCompilerArgs.add("-Xexpect-actual-classes")
                    // For not needing to add `ExperimentalCoroutinesApi`
                    freeCompilerArgs.add("-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi")
                    // For not needing to add `ExperimentalUuidApi`
                    freeCompilerArgs.add("-opt-in=kotlin.uuid.ExperimentalUuidApi")
                    // For you specific case you would add `kotlin.ExperimentalStdlibApi`
                    freeCompilerArgs.add("-opt-in=kotlin.ExperimentalStdlibApi")
                }
            }
        }
    }
}
OR you can have something like this
Copy code
kotlin {
    sourceSets {
        all {
            languageSettings {
                optIn("kotlin.uuid.ExperimentalUuidApi")
            }
        }
       // OR Per target
       commonTest {
            languageSettings {
                optIn("kotlin.uuid.ExperimentalUuidApi")
            }
        }
    }
}
t
Copy code
kotlin {
    compilerOptions.optIn(listOf("..."))
}
❤️ 1
g
> compilerOptions.optIn(listOf("...")) at first got
Unresolved reference.
and had to change to
compilerOptions.optIn = listOf("...")
. that also did not work. still get errors like
This declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
> compilerOptions { > // For the usage of expect/actual warning > freeCompilerArgs.add("-Xexpect-actual-classes") > // For not needing to add
ExperimentalCoroutinesApi
> freeCompilerArgs.add("-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi") > // For not needing to add
ExperimentalUuidApi
> freeCompilerArgs.add("-opt-in=kotlin.uuid.ExperimentalUuidApi") > // For you specific case you would add
kotlin.ExperimentalStdlibApi
> freeCompilerArgs.add("-opt-in=kotlin.ExperimentalStdlibApi") > } that will only work for that specific classes. Also other libraries will have their opt-in annotations for example compose. it's just annoying to keep adding those annotations, especially for small projects that is just for learning.
t
@Giorgi at the moment such case is not support and you should file a new Kotlin feature request to add a new compiler argument to optin to all
@OptIn
preset in the compilation: https://kotl.in/issue
👀 1