Spring Boot Gradle Plugin version and dependency mismatch in gradle project

145 Views Asked by At

I have a spring cloud multi-module project.

Spring Boot Gradle Plugin version:

id("org.springframework.boot") version "3.1.5"
id("io.spring.dependency-management") version "1.1.3"

Everything was running fine until recently when I had to upgrade the spring-data-jpa version due to an issue.

This project is in the validation phase, so I'm going to just upgrade the spring boot version from 3.1.5 to 3.2.0.

But when I change the versions of org.springframework.boot, io.spring.dependency-management and org.springframework.cloud:spring-cloud-dependencies and execute the prepareKotlinBuildScriptModel, the dependency version of jpa is still 3.1.2, which is confusing me. Am I missing some gradle configuration?

build.gradle.kts of main project:

plugins {
    java
    id("org.springframework.boot") version "3.2.0"
    id("io.spring.dependency-management") version "1.1.4"
}

group = "com.fabrication.base"
version = "0.0.1-SNAPSHOT"

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

allprojects {
    apply(plugin = "java")

    repositories {
        maven {
            setUrl("https://maven.aliyun.com/repository/public/")
        }
        mavenCentral()
    }

}

subprojects {

    apply(plugin = "org.springframework.boot")
    apply(plugin = "io.spring.dependency-management")

    java {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    dependencies {
        compileOnly("org.projectlombok:lombok")
        annotationProcessor("org.projectlombok:lombok")
    }

    dependencyManagement {
        imports {
            mavenBom("org.springframework.cloud:spring-cloud-dependencies:2023.0.0")
            mavenBom("com.alibaba.cloud:spring-cloud-alibaba-dependencies:2022.0.0.0")
            mavenBom("org.springdoc:springdoc-openapi:2.2.0")
        }
    }

    tasks.bootBuildImage {
        builder = "127.0.0.1:5000/paketobuildpacks-builder:latest"
        runImage = "127.0.0.1:5000/paketobuildpacks-run:latest"
        imageName = "127.0.0.1:5000/${project.name}:${project.version}"
        environment.put("BP_JVM_VERSION", java.sourceCompatibility.majorVersion)
        val bindingPath = "D:/Users/username/IdeaProjects-com/bindings"
        bindings.add("$bindingPath/files/:/tmp/files/")
        bindings.add("$bindingPath/dependency-mapping/:/platform/bindings/dependency-mapping/")
    }
}

build.gradle.kts of sub project:

group = "com.fabrication.base.sub"
version = "0.0.1-SNAPSHOT"

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.cloud:spring-cloud-starter")
    implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
    implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer")
    implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery")
    implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config")
    implementation("org.springdoc:springdoc-openapi-starter-webmvc-api")
    runtimeOnly("org.postgresql:postgresql")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.test {
    useJUnitPlatform()
}

gradle base-sub:dependencyManagement part of output:

0:06:08: Executing 'base-sub:dependencyManagement'...


> Task :base-sub:dependencyManagement

------------------------------------------------------------
Project :base-sub
------------------------------------------------------------

global - Default dependency management for all configurations
    ...
    
    org.hibernate.orm:hibernate-core 6.2.6.Final
    ...
    org.springframework.boot:spring-boot-starter-data-jdbc 3.1.2
    org.springframework.boot:spring-boot-starter-data-jpa 3.1.2
    ...
    org.springframework.cloud:spring-cloud-gateway-mvc 4.1.0
    org.springframework.cloud:spring-cloud-gateway-server 4.1.0
    org.springframework.cloud:spring-cloud-gateway-server-mvc 4.1.0
    org.springframework.cloud:spring-cloud-gateway-webflux 4.1.0
    ...
...

BUILD SUCCESSFUL in 262ms
1 actionable task: 1 executed
0:06:09: Execution finished 'base-sub:dependencyManagement'.

Currently I manually specified the version of hibernate-core and the jpa query works fine.

implementation("org.springframework.boot:spring-boot-starter-data-jpa"){
    exclude("org.hibernate.orm:hibernate-core:6.2.6.Final")
}
implementation("org.hibernate.orm:hibernate-core:6.3.1.Final")

But the issue of version correspondence is still not solved.

I think the version of spring dependencies should be managed by Spring Boot Gradle Plugin and not customized by me.

0

There are 0 best solutions below