How to work around issue 2553 (Native Libaries are in the wrong directory)?

I’m trying to use Gradle to build an application that uses JOGL. I have specified the following dependencies:

dependencies {
    compile 'org.jogamp.jogl:jogl-all:2.+'
    compile 'org.jogamp.jogl:jogl-all:2.+:natives-macosx-universal'
      compile 'org.jogamp.gluegen:gluegen-rt:2.+'
    compile 'org.jogamp.gluegen:gluegen-rt:2.+:natives-macosx-universal'
}

Gradle resolves these dependencies, and the project builds fine. Problems arise, however, when I try to run my application, as it crashes with the following stack trace:

Catched ZipException: error in opening zip file, while TempJarCache.bootstrapNativeLib() of jar:file:/Users/private/.gradle/caches/artifacts-26/filestore/org.jogamp.gluegen/gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/gluegen-rt-2.0.2-natives-macosx-universal.jar!/ (file:/Users/private/.gradle/caches/artifacts-26/filestore/org.jogamp.gluegen/gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/ + gluegen-rt-2.0.2-natives-macosx-universal.jar)
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /System/Library/Frameworks/gluegen-rt.Framework/gluegen-rt
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1706)
 at java.lang.Runtime.load0(Runtime.java:770)
 at java.lang.System.load(System.java:1020)
 at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:468)
 at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:63)
 at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:94)
 at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:332)
 at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
 at com.jogamp.common.os.Platform$1.run(Platform.java:210)
 at java.security.AccessController.doPrivileged(Native Method)
 at com.jogamp.common.os.Platform.<clinit>(Platform.java:173)
 at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
 at org.aeriksson.plotter.renderer.Window.createCanvas(Window.java:38)
 at org.aeriksson.plotter.renderer.Window.init(Window.java:29)
 at org.aeriksson.plotter.Main.main(Main.java:20)

This seems to occur since jogl-all-2.0.2.jar tries to load jogl-all-2.0.2-natives-macosx-universal.jar at runtime, but can not find it since Gradle places these two files in different directories (gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/ vs. gluegen-rt/2.0.2/jar/7de4fb110a95f67c1cc1e122d508cd63e137e2eb/).

As mentioned in http://issues.gradle.org/browse/GRADLE-2553, this problem can be avoided by copying jogl-all-2.0.2-natives-macosx-universal.jar to the gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/ directory (and doing the same thing for JOGL). However, this does not seem like a very elegant or robust solution.

Is there a better way to ensure that the libraries are loaded correctly (for instance, by forcing the jars to be placed in the same directory through build.gradle)?

The best solution is to copy the Jars to some directory and lay them out as needed by your application. The Gradle cache should be left untouched.

This problem is basically the same I have at http://forums.gradle.org/gradle/topics/application-plugin-run-task-should-first-consolidate-classes-and-resources-folder-or-depend-on-installapp-or-stuff-like-weld-se and the same solution can be used. Overwrite the run task like I have shown in that thread, and everything should work like a charm.