我有一个依赖于 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
和文件,但仍添加文件:so
lib
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