我有一个依赖于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不再将dll
和so
文件添加到Eclipse类路径中,但仍会添加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
答案 0 :(得分:0)
我对Gradle生成的Eclipse构建路径有同样的问题但是我必须通过以下方式调整(部分... lib
文件不被尊重?)解决方案:
minusConfigurations += configurations.natives
到minusConfigurations += [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')
}
答案 1 :(得分:0)
I had a similar problem with eclipse and gradle 4.3. I finally found a solution, thought I share it with you all:
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)
}
}
}
}