关于如何从fatJar中排除单个文件,有很多重复的答案。通常,文件被排除在META-INF中,它们被排除是因为文件名冲突,或者因为它是从依赖项libarar Jar文件复制的签名,而该文件对新创建的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,这样用户必须有可用的库才能执行生成的fat 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文件的内容仍然会复制到生成的fat jar中。
谢谢。其动机是将我的Java应用程序发布到提供自己的安全库BouncyCastle的系统(例如Debian Linux),而不是嵌入该安全库的未签名副本。
发布于 2020-01-08 17:43:50
我不知道excludes和includes是如何工作的,但我希望这些配置在类文件级别上工作,因为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
}https://stackoverflow.com/questions/59642428
复制相似问题