Can anybody tell me whether it is possible to buil...
# compose-desktop
m
Can anybody tell me whether it is possible to build a library which uses compose with Maven instead of Gradle? I have a multi-module Maven project and would like to add a module which makes use of Compose. Compiling Kotlin with Maven is no problem but with Compose I am not sure.
🚫 1
1
j
If you are just asking whether it's possible then yes, it's possible. Compose is just a Kotlin compiler plugin and a runtime library. If you are asking for specific instructions I cannot help you. Broadly, compiler plugins can be added to the Kotlin compiler through command-line properties which specify the plugin classpath. You would have to aggregate the transitive dependency set of the Compose compiler plugin and put it on the Kotlin compiler plugin classpath. After that you just need a normal dependency on the Compose runtime and any downstream helper libraries (like Compose UI).
All that the Gradle plugin is doing is using a standard Gradle configuration (think: dependency container) for all of the compiler plugins to add their dependencies so that their transitive dependencies can be resolved as one set. Then it bundles them up into a classpath and passes it as a property to the Kotlin compiler.
a
It should not be hard for a pure desktop project. We don’t provide the official tooling and support, though. In case of MPP it’s probably possible in theory, but too painful in practise (all MPP tooling is tied to Gradle). Compiling a pure desktop project requires: •
org.jetbrains.compose.compiler:compiler
artifact in compiler plugin classpath; • Compose JVM dependencies for compilation and at runtime. E.g.
org.jetbrains.compose.desktop:desktop-jvm-macos-x64
and its transitive dependencies. Dependencies of interest can be found in the source of our Gradle plugin https://github.com/JetBrains/compose-jb/blob/master/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt#L111
-XuseIR
compiler argument (because Compose compiler plugin supports only new backend IR); • A declaration of JetBrains Compose Maven repository (https://maven.pkg.jetbrains.space/public/p/compose/dev). That’s pretty much it for a simple desktop app. Then it can be ran as any other Java app. It can be packaged into native installers as well using
jpackage
, there are probably existing Maven plugins for that. Under the hood it’s just Maven artifacts, the compiler plugin and a few compiler arguments (and a few other tools for bundling distributions).
m
Many thanks for the detailed answers. I now have to decide whether following that route or splitting the project is the better long-term strategy.
👍 1
I did some experiments. So far I failed but maybe my general understanding is just wrong. For what exactly is the compiler plugin needed? I would just like to put some code with dependencies to
androidx.compose.ui.graphics
into that library, i.e., no
@Composable
functions. Just some plain graphics stuff. Can such code be compiled as plain Kotlin code without the compiler plugin or is it always needed for all Compose code?
I can now answer my own question. It works! 😀 I’ve put all the graphics stuff into a Maven sub-module of my graphics framework and just declared that as a dependency in my main Compose project which uses Gradle as its build system. The Maven project now consists of three sub-modules core, jfx and cmp where core and jfx (JavaFX) are written in Java and cmp (Compose) is written in Kotlin. This all works without using the Compose compiler plugin.