gpt4 book ai didi

gradle:排除制作 fatJar 的依赖

转载 作者:行者123 更新时间:2023-12-03 03:41:14 25 4
gpt4 key购买 nike

关于如何从 fatJar 中排除单个文件有很多重复的答案。通常,文件被排除在 META-INF 中,并且由于文件名冲突,或者因为它是从依赖库文件复制的签名,该签名对新创建的 Jar 文件无效。

Maven 示例:
How can I tell which signed jar is causing maven-shade-plugin to fail?

gradle 示例:
Removing Jar Signatures in Gradle Build

但是,这些解决方案仅单独删除了有问题的文件。

我们如何制作一个排除了特定依赖库(而不是该库中的单个文件)的 fatJar?

例如,问题 36226033 ,很容易排除从 BouncyCaSTLe 复制过来的签名,但是有没有办法排除依赖库 bcprov-jdk15on-*.jar完全,以便用户必须拥有可用的库才能执行生成的胖 Jar?

事实证明这是行不通的:

task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.alphawallet.scripttool.Main'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
exclude('**/bcprov-jdk15on-1.62.jar')
with jar
}


exclude('**/bcprov-jdk15on-1.62.jar') ,该 jar 文件的内容仍会复制到生成的胖 jar 中。

谢谢。动机是将我的 Java 应用程序发送到提供自己的安全库 BouncyCaSTLe(例如 Debian Linux)的系统,而不是嵌入该安全库的未签名副本。

最佳答案

不知道怎么样excludesincludes工作,但我希望这些配置在类文件级别上工作,因为 jar 正在处理。

它不适用于 jar 。

我会选择这个解决方案:

task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.alphawallet.scripttool.Main'
}
baseName = project.name + '-all'
configurations.compile.findAll { file ->
// file is of type java.io.File
// when true, jar file is unziped and added
file.name != "bcprov-jdk15on-1.62.jar"
}.sort { it.name }
.collect { file ->
logger.info("Including file: ${file.name}")
file.isDirectory() ? file : zipTree(file)
}
with jar
}

关于gradle:排除制作 fatJar 的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59642428/

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