Search code examples
s4sdk

Dependencies put twice into Spring Boot (>2.x) jar when using Gradle


adding Cloud SDK like this for CF: compile "com.sap.cloud.s4hana:s4hana-all:${cloudSDKVersion}" compile ("com.sap.cloud.s4hana.cloudplatform:scp-cf:${cloudSDKVersion}") leads to duplicate jars in spring boot jar which is deployed to CF. examples: core-2.3.1.jar connectivity-2.3.1.jar

  • This leads to :
    • ClassNotFoundExceptions during runtime
    • prevents cf push commands with error: 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

Solution

  • gradle skips the component name when building the boot package.

    After some googling around this was the solution: 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}"
        })
    }