2

我有一个依赖于 Sigar 库的 Gradle 项目,它使用本机库(作为其传递依赖项)。这是依赖树的相关片段:

+--- sigar:sigar:2.0
|    +--- libsigar-amd64-linux:libsigar-amd64-linux:1.0
|    +--- libsigar-ia64-linux:libsigar-ia64-linux:1.0
|    +--- libsigar-x86-linux:libsigar-x86-linux:1.0
|    +--- sigar-amd64-winnt:sigar-amd64-winnt:1.0
|    \--- sigar-x86-winnt:sigar-x86-winnt:1.0

不幸的是,Gradle 似乎没有认识到这些是本机库,并将它们添加到 eclipse 类路径中,就像它们是常规库一样jar。这会导致 Eclipse 中的错误:

Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/libsigar-x86-linux/libsigar-x86-linux/1.0/so/c9af548445db750ad46e8beb3e77c58ff2315f3f/libsigar-x86-linux-1.0.so' in project 'myproject' cannot be read or is not a valid ZIP file   
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/libsigar-ia64-linux/libsigar-ia64-linux/1.0/so/19d7aa37a3c40b6812a80eca518c6b81fd5c8416/libsigar-ia64-linux-1.0.so' in project 'myproject' cannot be read or is not a valid ZIP file    
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/libsigar-amd64-linux/libsigar-amd64-linux/1.0/so/9481ceafe276c92327f8f3389c5e1c791eac6a81/libsigar-amd64-linux-1.0.so' in project 'myproject' cannot be read or is not a valid ZIP file 
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-x86-winnt/sigar-x86-winnt/1.0/lib/1a608efcfd2e8358862b7dce02892fa98d63c97b/sigar-x86-winnt-1.0.lib' in project 'myproject' cannot be read or is not a valid ZIP file  myproject       
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-x86-winnt/sigar-x86-winnt/1.0/dll/14dfa28510c62eee00812e8d231f72ec69ac45b9/sigar-x86-winnt-1.0.dll' in project 'myproject' cannot be read or is not a valid ZIP file  myproject       
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-amd64-winnt/sigar-amd64-winnt/1.0/dll/b326449439e280c723ac45ada770a8d65a1272cc/sigar-amd64-winnt-1.0.dll' in project 'myproject' cannot be read or is not a valid ZIP file    myproject       
The project cannot be built until build path errors are resolved    myproject       

我怎样才能解决这个问题?

编辑:

我试图从 Eclipse 类路径中排除本机依赖项,​​如下所示:

configurations {
    natives
    compile.extendsFrom(natives)
}

eclipse {
    classpath {
        minusConfigurations += configurations.natives
        ...
    }
}

dependencies {
    ...

    compile("sigar:sigar:2.0")
    natives("libsigar-amd64-linux:libsigar-amd64-linux:1.0")
    natives("libsigar-ia64-linux:libsigar-ia64-linux:1.0")
    natives("libsigar-x86-linux:libsigar-x86-linux:1.0")
    natives("sigar-amd64-winnt:sigar-amd64-winnt:1.0")
    natives("sigar-x86-winnt:sigar-x86-winnt:1.0")

    ...
}

这仅部分有效。Gradle 不再向 Eclipse 类路径添加dll和文件,但仍添加文件:solib

Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-x86-winnt/sigar-x86-winnt/1.0/lib/1a608efcfd2e8358862b7dce02892fa98d63c97b/sigar-x86-winnt-1.0.lib' in project 'myproject' cannot be read or is not a valid ZIP file
4

2 回答 2

0

我对 Gradle 生成的 Eclipse 构建路径有同样的问题,但我必须通过lib以下方式调整(部分..文件不被尊重?)解决方案:

  • 较新的 Groovy 版本需要适应从minusConfigurations += configurations.nativesminusConfigurations += [configurations.natives]
  • 我有一个安装库的普通目录,而不是存储库。它对我有用native files,而不是在该部分natives内使用(仅在存储库中搜索)dependencies

build.gradle摘录这两个变化:

apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'java'

..

configurations{
    natives
    compile.extendsFrom(natives)
  }

sourceSets.main.compileClasspath += [configurations.provided]
eclipse {
    classpath {
      minusConfigurations += [configurations.natives]
    }
  }

dependencies {
    native files('D:/lib/nativeDLL.dll')
}
于 2015-03-11T17:35:27.437 回答
0

我对 eclipse 和 gradle 4.3 也有类似的问题。终于找到解决办法了,想和大家分享一下:

eclipse {
    classpath {
       file {
            whenMerged { classpath ->
                java.util.List wanted = new java.util.ArrayList()
                def entries = classpath.getEntries()
                entries.each {
                    if (it.path.endsWith('.so')) {
                        println('Removing native library: ' + it.path + ' from eclipse classpath (unreadable to eclipse)')
                    } else {
                        wanted.add(it)
                    }
                }
                classpath.setEntries(wanted)
             }
        }
    }
}
于 2019-03-06T11:33:39.020 回答