Is it possible to set up my project such that I ca...
# compose-desktop
z
Is it possible to set up my project such that I can use expect/actual for platform dependent code? My application runs on both windows and linux
👍 2
j
I think you can use normal polymorphism (i.e., an interface and two implementations) more simply than what it would take to actually use expect/actual
z
Maybe that would work. Just not sure how to implement the part to choose which implementation to use
j
You would check against
System.getProperty("os.name")
z
I suppose that would work. I was thinking more something where I can have the windows executable contain the windows implementation and vice versa rather than both platforms containing both implementations
j
i mean, you can do that but it's just more complicated to set up
z
I'm willing to try it and learn something new
j
I'm pretty sure the solution is to abandon Compose Desktop's built-in packaging, have OS-specific jvm targets, and use jlink/jpackage to build your own binaries.
👍🏻 1
As a bonus, unlike Compose Desktop's built-in packaging support, you can "cross-compile" (or, cross-bundle) the packages for Windows and Linux on whatever OS you want as long as you have that OS's JDK.
m
@jw Could you please elaborate on that? Jpackage has no cross-building capabilities. (Which is a pity.)
m
I will soon be starting a Compose Desktop project that should run on Linux and Windows, is the built-in packaging not good? For platform specific code I was thinking to use separate Gradle modules per platform, containing the implementations of common interfaces.
m
@Marcin Wisniowski The built-in packaging is OK but has a few limitations. E.g., you cannot cross build for another platform. I.e., you have to run the build on the same platform for which you want to create the build. This is mostly because jpackage uses some platform specific tools for certain tasks. I use GitHub hosted action runners to solve that issue. The only problem is that GitHub still does not have runners for all platforms, e.g., ARM macs but Rosetta 2 comes to the rescue in this case.