使用Gradle时将依赖项放入Spring Boot(> 2.x)jar中两次

时间:2018-09-05 11:49:43

标签: s4sdk

为CF添加这样的Cloud SDK: compile "com.sap.cloud.s4hana:s4hana-all:${cloudSDKVersion}" compile ("com.sap.cloud.s4hana.cloudplatform:scp-cf:${cloudSDKVersion}") 导致弹簧靴子罐中有重复的罐子,该罐子部署到CF。 例子: core-2.3.1.jar connectivity-2.3.1.jar

  • 这导致:
    • 运行时发生ClassNotFoundExceptions
    • 防止cf push命令出现错误: 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

1 个答案:

答案 0 :(得分:5)

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}"
    })
}