Is there a way to introduce a library-specific exp...
# announcements
e
Is there a way to introduce a library-specific experimental marker annotation that serves as an alias to a set of other experimental annotations? Let’s say the library uses API marked with
@ObsoleteCoroutinesApi
and
@ExperimentalCoroutinesApi
and I don’t want library users to opt into using any of those everywhere in their code, just in the scope of my library. I imagine it has to be something like this:
Copy code
@Experimental
@UseExperimental(ObsoleteCoroutinesApi::class, ExperimentalCoroutinesApi::class)
annotation class MyExperimental
but the IDE won’t allow me to use
@UseExperimental(MyExperimental::class)
in place of e.g.
@UseExperimental(ObsoleteCoroutinesApi::class)
in the library code. Is there a proper way to set it up? Does this approach make sense?
l
Alternatively, you can opt-in for the whole library from Gradle.
e
Something like this?
Copy code
compileKotlin {
    kotlinOptions {
        freeCompilerArgs += "-Xuse-experimental=ObsoleteCoroutinesApi"
        freeCompilerArgs += "-Xuse-experimental=ExperimentalCoroutinesApi"
        freeCompilerArgs += "-Xexperimental=MyExperimental"
    }
}
l
Yes
e
Makes sense, thanks!