gpt4 book ai didi

java - 从目录Gradle Fatjar

转载 作者:行者123 更新时间:2023-12-03 03:18:07 62 4
gpt4 key购买 nike

我有一个文件夹($buildDir/some/lib),里面有很多jar。我想创建一个 jar ,其中所有 jar 都在里面但未压缩。我已经尝试了很多事情,但是所有这些都失败了,包括以下一项:

task fatJar(type: Jar, dependsOn: 'someTask') {
manifest {
attributes 'Main-Class': 'some.Main'
}
baseName = project.name + '-all'
from ("$buildDir/some/lib") {
eachFile { it.isDirectory() ? it : zipTree(it) } }

with jar
}

在这种情况下,错误是:

Cannot convert the provided notation to a File or URI: file '/path/to/the/buidDir/above/someJar.jar'.



有什么帮助吗?

编辑:
我将其更改为此,但是它仍然无法正常工作..复制了jar,但是没有将它们拆包..帮助!为什么这么难?
task fatJar(....) {
manifest {
.....
}
baseName = project.name + '-all'
FileCollection collection = files("$buildDir/some/lib")
from collection.collect { it.isDirectory() ? it : zipTree(it) }

with jar
}

最佳答案

您可以执行以下操作:

task fatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'some.Main'
}
baseName = project.name + '-all'
project.fileTree("$buildDir/some/lib").forEach { jarFile ->
from zipTree(jarFile )
}
with jar
}

注意

在第一个解决方案中,您会收到错误“无法将提供的符号转换为文件或URI ...”,因为在 eachFile闭包中(请参阅 CopySpec.eachFile(),您可以操作 FileCopyDetails对象,而 zipTree方法需要使用Zip Path。一种解决方案是使用 getPath()方法: eachFile { it.isDirectory() ? it : zipTree(it.getPath()) } }

关于java - 从目录Gradle Fatjar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53141024/

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com