Hey everyone! How can I add JavaFX to the desktop ...
# multiplatform
a
Hey everyone! How can I add JavaFX to the desktop target of my KMP project? When I try to add this [id("org.openjfx.javafxplugin") version "0.0.10" apply false] plugin I get the following error:
Copy code
A problem occurred configuring project ':composeApp'.
> Failed to notify project evaluation listener.
   > The 'java' plugin has been applied, but it is not compatible with the Android plugins.
   > No element of the collection was transformed to a non-null value.
More in🧵
I started the project back in September with the Compose Multiplatform Wizard, and the project setup looks like this, with two build.gradle files.
One only has a plugin clause, and the other one is like this:
Copy code
plugins { ... }

kotlin {
    androidTarget { ... }

    jvm("desktop")

    sourceSets {
        val commonMain by getting {
            dependencies { ... }
        }

        val androidMain by getting {
            dependencies { ... }
        }

        val desktopMain by getting {
            dependencies { ... }
        }

    }
}

android { ... }

compose.desktop {
    application {
        mainClass = "MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            ...
        }
    }
}
c
As you can see, the Android plugins cannot be applied in the same project as the Java plugin, and the JavaFX plugin requires the Java plugin. The simplest solution would be to split your repository into multiple projects, for example:
Copy code
your_repository/
    shared/ ← your existing project
        src/commonMain/
        src/androidMain/
        src/desktopMain/
        build.gradle.kts
    android/ ← new project with only Android stuff
        src/androidMain/
        build.gradle.kts
    desktop/ ← new project with only JavaFX stuff
        src/desktopMain/
        build.gradle.kts
This way, you can apply the Android plugin in
:android
and the JavaFX plugin in
:desktop
, and they won't fight
a
Thanks for the help, I was hoping that I wouldn't have to do that. But oh well
c
Honestly, it's a bit scary at first, but once you've done it once or twice you'll see it's really easy. Single-project repositories are quite rare.