Hi all. I have a multiplatform project where I am...
# multiplatform
n
Hi all. I have a multiplatform project where I am trying to target both Android and generic JVM targets. The issue is, both of these targets have to have different gradle plugins applied, so I cannot put all of the plugins at the top of my root build.gradle file. So my question is: Where should I apply a Gradle plugin so that it will only be applied for one platform? I have tried putting them in:
Copy code
Kotlin {
    platformA {
        // apply plugins for platformA here
    }
    platformB {
        // apply plugins for platformB here
    }
}
but this seems to cause issues. Right now, I get the error "The java plugin has been applied, but it is not compatible with the Android plugins". It seems as though it is trying to apply the plugins during the initial gradle config, not when building a specific platform. Is it possible to do what I am trying to do here?
🚫 1
For context, my goal is to use the expect-actual mechanism to provide a common API between two platforms (one JVM, one Android) which both have different sets of dependencies, and different gradle plugins applied. Is this sort of thing possible at all right now? Is there maybe a different way to do it then I'm going about right now?
e
not directly, no. plugins apply to the whole project at configuration time
you will either need to fix the plugins to work with multiplatform, or apply them in separate projects
n
Hmm... and I assume it's not possible to have an actual implement an expect if it's in a different project? (I'd be happy if this were true, but I couldn't find anything in the docs to that effect)
e
right, expect/actual have to be in the same module
n
Ahh, that's sad. Unfortunately I don't think I know enough about gradle to be able to fix the plugins. Going to have to find another approach to build the common API I suppose.
a
You can still go for a common submodule with shared code together with expect/actual for platform A and B. And then have specific submodules for platform A and B where you'd apply the gradle plugins
e
yes, that is what I meant by "or apply then in separate projects", although I can see if you were confused by the Gradle terminology of "project" mixed with the term "module" as used by most others