Multirelease with modules, java9

Hi.

I require a lwjgl module (org.lwjgl.vulkan.natives) in one of my modules. The compilation (as Spasi explained) fails on windows/linux as natives are not needed there (so its not available during the compilation).
If I remove the requires than it does compile on windows/linux/osx, but it does not run on OSX as the needed lib is not on the classpath during runtime.

The thing is that without requiring natives, after compilation and BEFORE jlinking, there is a

lwjgl-vulkan-3.2.1-SNAPSHOT-natives-macos.jar

in my mods directory, so I thought, I would just need to add that too when jlinking (on OSX) and it will be fine.

So I use jlink then:

jlink --module-path $JAVA_HOME/jmods:build/mods --add-modules org.lwjgl.vulkan.natives --add-modules spck.game --launcher APP=mymodule/Main --compress 2 --no-header-files --no-man-pages --strip-debug --output build/release

But

--add-modules org.lwjgl.vulkan.natives

did not help, it still fails to run on OSX as it does not find the moltenvk libs.

What did I miss?

The simple solution is to enable the artifact and “requires org.lwjgl.vulkan.natives” only when preparing a macOS build. Since jlink has to run on each target platform, it’s best to have it include only artifacts that will be used on that platform. The Maven/Gradle scripts generated by the build customizer on the LWJGL website, take care of that.

If you don’t want to edit your module-info.java (or have different versions of it), your jlink approach is on the correct path: Adding [icode]–add-modules org.lwjgl.vulkan.natives[/icode] to the jlink parameters ensures that the Vulkan natives artifact makes it into the linked image. However, it won’t be loaded at runtime because it’s missing from your application’s module-info. If [icode]–add-modules org.lwjgl.vulkan.natives[/icode] is also added to the application’s launch script, everything will be fine.

And it’s really as simple as you mentioned. My java9 knowledge lacked this info. Thx!