How to make platform specific builds of a Java project with platform specific dependencies?

My Java project has some platform specific dependencies. One of these is the Standard Widget Toolkit (SWT). The other is a custom native library(IE. .DLL on windows, .so on linux) which will be used through my own custom bindings using Java Native Access (JNA).

My intent is that it should be possible to build distributions of my Java project for all platforms on a single computer (probably using prebuilt versions of the native library and SWT). The output of building for all platforms would be a distribution for each platform I intend to support (eg. windows X86, windows X64, Linux X86, MacOSX, etc). A distribution being something like a zip file containing all dependencies and launch scripts.

When I have done searches about doing platform specific builds, the results seem to discuss just adjusting the dependencies depending on what the current OS environment is. This obviously will not cover the situation for building for multiple platforms on one computer.

Having been reading the Gradle documentation, I have read some of the native library compiling sections (this might be useful anyway for compiling the custom native library), and I am thinking is there any way I could use the platform stuff from that to build the various platform distributions of my Java project? If so could you give more details as the documentation only discusses this for doing native library compilation.

The alternative I am thinking of is whether I should be using multiple configurations, each configuration being for a specific platform and thus having the platform specific dependencies in each configuration. I assume I would need a task to build all configurations and tasks for building each configuration individually should I need to build just one platform.

Another option might be to go a similar route as JNA and include all binaries and load the right one at runtime. This probably would be reasonable for the custom native library as it is fairly small and I could make the custom bindings find the correct binary at runtime. However I do not feel this would be as possible for SWT, so another solution would still be needed.

What is the best way to achieve this building of platform specific distributions of a Java project? Is there any other way I have not thought of which may be better?

Thank you for any help.

1 Like