Using Gradle with native dependencies

前端 未结 1 627
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 08:03

I am trying to use Sigar in a Gradle project. Sigar distribution is by default provided with 2 types of files:

  • a JAR that contains classes
  • some native
相关标签:
1条回答
  • 2020-12-30 08:27

    A solution is to define a new gradle configuration that unzips JAR files at the desired location:

    project.ext.set('nativeLibsDir', "$buildDir/libs/natives")
    
    configurations {
        nativeBundle
    }
    
    dependencies {
        nativeBundle 'sigar:sigar:1.6.4:native'
    }
    
    task extractNativeBundle(type: Sync) {
        from {
            configurations.nativeBundle.collect { zipTree(it) }
        }
        into file(project.nativeLibsDir)
    }
    
    dist.dependsOn extractNativeBundle
    

    Then, this location must be put in java.library.path for tasks that depend on native libraries:

    systemProperty "java.library.path", project.nativeLibsDir
    
    0 讨论(0)
提交回复
热议问题