[SOLVED] Gradle/Natives problem

Started by mudlee, February 25, 2020, 14:41:03

Previous topic - Next topic

mudlee

Hi.

I've created a Gradle multi-project with Java9 modules, which cannot find natives somewhy. It works great with maven.
I have two projects, :core and :desktop, where :core contains all dependencies and :desktop depends on :core. Core exports transitive all of its dependencies:

module spck.core {
	requires transitive org.lwjgl;
	requires transitive org.lwjgl.bgfx;
	requires transitive org.lwjgl.glfw;
	requires transitive org.joml;

	exports spck.core;
}


Any idea?

Here is the problem itself:
[LWJGL] Version: 3.2.4 build 5
[LWJGL]          OS: Linux v5.3.0-40-generic
[LWJGL]         JRE: 11.0.4 amd64
[LWJGL]         JVM: OpenJDK 64-Bit Server VM v11.0.4+11 by AdoptOpenJDK
[LWJGL] Loading JNI library: lwjgl
[LWJGL]         Module: org.lwjgl
[LWJGL]         linux/x64/org/lwjgl/liblwjgl.so not found in java.library.path=/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
[LWJGL]         liblwjgl.so not found in java.library.path
[LWJGL] Failed to load a library. Possible solutions:
        a) Add the directory that contains the shared library to -Djava.library.path or -Dorg.lwjgl.librarypath.
        b) Add the JAR that contains the shared library to the classpath.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to locate library: liblwjgl.so
        at org.lwjgl/org.lwjgl.system.Library.loadSystem(Library.java:162)
        at org.lwjgl/org.lwjgl.system.Library.loadSystem(Library.java:62)
        at org.lwjgl/org.lwjgl.system.Library.<clinit>(Library.java:50)
        at org.lwjgl/org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:99)
        at org.lwjgl/org.lwjgl.system.Pointer$Default.<clinit>(Pointer.java:67)
        at spck.core/spck.core.Demo.run(Demo.java:48)
        at spck.desktop/spck.desktop.DesktopRunner.main(DesktopRunner.java:65)


The :core gradle project has the following dependencies (slightly changed the snippet from the lwjgl site):

dependencies {
    api platform("org.lwjgl:lwjgl-bom:$lwjglVersion")

    api "org.lwjgl:lwjgl"
    api "org.lwjgl:lwjgl-bgfx"
    api "org.lwjgl:lwjgl-glfw"
    runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-bgfx::$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
    api "org.joml:joml:${jomlVersion}"
}

mudlee

OK, looks like turning off Java9 modules solves the problem.
I use org.javamodularity.moduleplugin for Java 9 gradle modules.

How can I use lwjgl with this plugin?

mudlee

Aaaand solved.
After found out that the problem is in the module system, I quickly found this issue, where the solution sits: https://github.com/java9-modularity/gradle-modules-plugin/issues/126