使用 Gradle 时,依赖项会两次放入 Spring Boot (>2.x) jar
Dependencies put twice into Spring Boot (>2.x) jar when using Gradle
像这样为 CF 添加 Cloud SDK:
compile "com.sap.cloud.s4hana:s4hana-all:${cloudSDKVersion}"
compile ("com.sap.cloud.s4hana.cloudplatform:scp-cf:${cloudSDKVersion}")
导致部署到 CF 的 spring 引导 jar 中有重复的 jar。
例子:
core-2.3.1.jar
connectivity-2.3.1.jar
- 这导致:
- 运行时出现 ClassNotFoundExceptions
- 防止错误的 cf 推送命令:
Comparing local files to remote cache...
Aborting push: File BOOT-INF/lib/core-2.3.1.jar has been modified since the start of push. Validate the correct state of the file and try again.
FAILED
gradle 构建启动包时跳过组件名称。
经过谷歌搜索后,解决方案如下:
https://github.com/spring-projects/spring-boot/issues/10778
bootJar {
rootSpec.filesMatching('**/*.jar', { jar ->
String groupId = jar.file.parentFile.parentFile.parentFile.parentFile.name
jar.name = "$groupId-${jar.name}"
})
}
像这样为 CF 添加 Cloud SDK:
compile "com.sap.cloud.s4hana:s4hana-all:${cloudSDKVersion}"
compile ("com.sap.cloud.s4hana.cloudplatform:scp-cf:${cloudSDKVersion}")
导致部署到 CF 的 spring 引导 jar 中有重复的 jar。
例子:
core-2.3.1.jar
connectivity-2.3.1.jar
- 这导致:
- 运行时出现 ClassNotFoundExceptions
- 防止错误的 cf 推送命令:
Comparing local files to remote cache... Aborting push: File BOOT-INF/lib/core-2.3.1.jar has been modified since the start of push. Validate the correct state of the file and try again. FAILED
gradle 构建启动包时跳过组件名称。
经过谷歌搜索后,解决方案如下: https://github.com/spring-projects/spring-boot/issues/10778
bootJar {
rootSpec.filesMatching('**/*.jar', { jar ->
String groupId = jar.file.parentFile.parentFile.parentFile.parentFile.name
jar.name = "$groupId-${jar.name}"
})
}