关于如何从 fatJar 中排除单个文件有很多重复的答案。通常,文件被排除在 META-INF 中,并且由于文件名冲突,或者因为它是从依赖库文件复制的签名,该签名对新创建的 Jar 文件无效。
maven 示例: 如何判断哪个签名 jar 导致 maven-shade-plugin 失败?
gradle 示例: 在 Gradle Build 中删除 Jar 签名
但是,这些解决方案仅单独删除了有问题的文件。
我们如何制作一个排除了特定依赖库(而不是该库中的单个文件)的 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
}
Run Code Online (Sandbox Code Playgroud)
使用exclude('**/bcprov-jdk15on-1.62.jar'),该 jar 文件的内容仍会复制到生成的胖 jar 中。
谢谢。动机是将我的 …
尝试部署一个我在 Spring Boot 上使用 IntelliJ 中的 gradle 中的 jar 函数构建的 jar。它使用“bootrun”从我的 IDE 本地运行良好,但没有将 jar 放在 Linux 服务器上。服务器上的完整错误是
应用程序启动失败 org.springframework.beans.factory.BeanDefinitionStoreException:无法处理配置类 [haughton.icecreamapi.config.AppConfig] 的导入候选者;嵌套异常是 java.lang.IllegalArgumentException: 在 META-INF/spring.factories 中找不到自动配置类。如果您使用自定义包装,请确保该文件正确。
我的构建.gradle
group 'IceCreamApiCA1'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories{
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}") }
}
// Apply the Spring Boot plugin
//apply plugin: 'spring-boot'
apply plugin: 'org.springframework.boot'
// Apply the Java plugin (expects src/main/java to be source folder)
apply plugin: 'java'
// Specify the location where our dependencies …Run Code Online (Sandbox Code Playgroud)