title: Using Gradle with native dependencies
body: <p>I am trying to use <a href="https://support.hyperic.com/display/SIGAR/Home">Sigar</a> in a Gradle project. Sigar distribution is by default provided with 2 types of files:</p>
  
  <ul>
  <li>a JAR that contains classes</li>
  <li>some native files (.so, dylib, .dll)</li>
  </ul>
  
  <p>My purpose is to repackage these files so that I can use them as dependencies deployed and downloaded on-demand from a personal Maven repository.</p>
  
  <p>My first try was to define dependencies as files in order to check that my application is working as expected before to repackage. Below is the Gradle code I used for my first test that works:</p>
  
  <pre><code>dependencies {
    compile files("${rootDir}/lib/sigar/sigar.jar")
    runtime fileTree(dir: "${rootDir}/lib/sigar/", exclude: "*.jar")
  }
  </code></pre>
  
  <p>Then, I have repackaged Sigar native files into a JAR and renamed the other one to match rules for maven artifacts since I want to deploy them in a Maven repository. Below is what I get:</p>
  
  <ul>
  <li>sigar-1.6.4.jar (contains .class files)</li>
  <li>sigar-1.6.4-native.jar (contains .dylib, .so, and .dll files at the root)</li>
  </ul>
  
  <p>The next step was to deploy these files in my custom repository. Then, I have updated my <code>build.gradle</code> as follows:</p>
  
  <pre><code>dependencies {
    compile 'sigar:sigar:1.6.4'
    runtime 'sigar:sigar:1.6.4:native'
  }
  </code></pre>
  
  <p>Unfortunately, when I do a <code>gradle clean build</code>, new dependencies are fetched but native libraries can no longer be found at runtime since now I get the following exception:  </p>
  
  <pre><code>Error thrown in postRegister method: rethrowing &lt;java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Sigar.getCpuInfoList()[Lorg/hyperic/sigar/CpuInfo;&gt;
  </code></pre>
  
  <p>Consequently, I am looking for a solution to fetch and to link native files to my Java app like for other dependencies. Any advice, comment, suggestion, help, solution, etc. are welcome ;)  </p>