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(
 at java.lang.Runtime.load0(
 at java.lang.System.load(
 at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(
 at com.jogamp.common.jvm.JNILibLoaderBase.access$000(
 at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(
 at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(
 at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(
 at com.jogamp.common.os.Platform$
 at Method)
 at com.jogamp.common.os.Platform.<clinit>(
 at org.aeriksson.plotter.renderer.Window.createCanvas(
 at org.aeriksson.plotter.renderer.Window.init(
 at org.aeriksson.plotter.Main.main(

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, 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 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.