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

Mat*_*eld 3 s4sdk

为CF添加这样的云SDK: compile "com.sap.cloud.s4hana:s4hana-all:${cloudSDKVersion}" compile ("com.sap.cloud.s4hana.cloudplatform:scp-cf:${cloudSDKVersion}") 导致弹簧启动jar中的重复jar,它被部署到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

Mat*_*eld 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}"
    })
}
Run Code Online (Sandbox Code Playgroud)