I'm trying to get a new LWJGL project running. I'd like to use gradle so that I can achieve some platform independency. However, I can't figure out how to set up gradle so that my program will find the LWJGL natives at runtime. All of the posts which I can find about this suggest setting your -Djava.library.path explicitly, which defeats the whole point of using gradle. Is there a way I can set up my build file so that it is machine independent?
root build.gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
project.ext.lwjglVersion = "3.0.0a"
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath "org.lwjgl:lwjgl:${lwjglVersion}"
classpath "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-windows"
classpath "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-linux"
classpath "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-osx"
}
}
allprojects {
version = '1.0'
ext {
appName = "AssetEditor"
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":AssetEditorDesktop") {
apply plugin: "java"
dependencies {
compile project(":AssetEditorCore")
compile "org.lwjgl:lwjgl:${lwjglVersion}"
compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-windows"
compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-linux"
compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-osx"
}
}
project(":AssetEditorCore") {
apply plugin: "java"
dependencies {
compile "org.lwjgl:lwjgl:${lwjglVersion}"
compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-windows"
compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-linux"
compile "org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-osx"
}
}
subproject build.gradle:
apply plugin: "java"
sourceCompatibility = 1.8
project.ext.mainClassName = "com.kitfox.assetEd.ui.AssetEditorMain"
project.ext.assetsDir = new File("assets");
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
// jvmArgs = '-Djava.library.path=/path/to/native/macosx'
}
task dist(type: Jar) {
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);
manifest {
attributes 'Main-Class': project.mainClassName
}
}
dist.dependsOn classes
error:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.lwjgl.LWJGLUtil.loadLibrarySystem(LWJGLUtil.java:337)
at org.lwjgl.Sys$1.run(Sys.java:36)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.<clinit>(Sys.java:33)
at org.lwjgl.LWJGLUtil.initialize(LWJGLUtil.java:309)
at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:35)
at org.lwjgl.openal.ALC10.alcOpenDevice(ALC10.java:137)
at com.kitfox.assetEd.ui.audio.Decoder.<init>(Decoder.java:88)
at com.kitfox.assetEd.ui.audio.Decoder.<init>(Decoder.java:78)
at com.kitfox.assetEd.ui.AssetEditorMain.<init>(AssetEditorMain.java:29)
at com.kitfox.assetEd.ui.AssetEditorMain$1.run(AssetEditorMain.java:104)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)