https://kotlinlang.org logo
#announcements
Title
# announcements
e

egorand

08/19/2019, 6:51 PM
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

louiscad

08/19/2019, 8:09 PM
Alternatively, you can opt-in for the whole library from Gradle.
e

egorand

08/19/2019, 8:22 PM
Something like this?
Copy code
compileKotlin {
    kotlinOptions {
        freeCompilerArgs += "-Xuse-experimental=ObsoleteCoroutinesApi"
        freeCompilerArgs += "-Xuse-experimental=ExperimentalCoroutinesApi"
        freeCompilerArgs += "-Xexperimental=MyExperimental"
    }
}
l

louiscad

08/19/2019, 9:16 PM
Yes
e

egorand

08/20/2019, 11:44 AM
Makes sense, thanks!
3 Views