Can the K2 plugin be used alongside the old compil...
# compiler
c
Can the K2 plugin be used alongside the old compiler plugin? (from the user’s point of view)
y
Yes since it just depends on whether the compiler argument for K2 is passed in or not. Your k2 plugin will most likely even be included in the same
ComponentRegistrar
, so yes it is compatible. Just be careful though that your IR backend needs to be able to handle code both from the old FE frontend and also the FIR (K2) frontend
c
So can I also apply the old compiler plugin (compose) that does not support K2 at the same time, and the new compiler plugin developed with K2 API?
y
Yes, but a user won't be able to use both at the same time IF compose relies on the old frontend. Basically, the backend right now is unified (it's all IR) and that is the same for K2, but the frontend is different, meaning that if Compose does some frontend shenanigans (which I think it might do? for like preventing you from calling
@Composable
functions outside of non-Composables) then you might find weird errors happening. Compose also most likely will receive a K2 update since again they don't rely on frontend that extensively AFAIK.
c
Thank you for your explanation!
d
Also note that even pure backend plugins may use some API (descriptors and
BindingContext
) which are deprecated but still accessible in combination of FE 1.0 + IR backend So authors of those plugins should fix them before marking plugin as K2 compatible
c
In fact, I’m just going to use the K2 API to develop a compiler plugin for my own use, but at the same time, I use many other old compiler plugins (compose, realm-kotlin), which have not yet supported K2. So I’m just afraid that I can’t use them at the same time. 😶
d
In such setup you could not use everything at once
c
In such setup you could not use everything at once
Uh... Do you mean that the following will fail? So I have to wait for other plugins to support the K2 API?
Copy code
plugins {
    id("org.jetbrains.compose") // Old compiler
    id("io.realm.kotlin") // Old compiler
    id("my.k2.compiler.plugin") // K2 compiler
}
d
Yep. If you compiler your project with K2, only
my.k2.compiler.plugin
will work With K1 compiler only
compose
and
realm
But if you enable some plugin with both frontends support (e.g.
allopen
) then it will work with both frontends