A minimal reproducible build.gradle:

apply plugin: 'java'

dependencies {
    testImplementation platform('org.springframework.boot:spring-boot-dependencies:2.5.3')
    constraints {
        testImplementation 'org.mockito:mockito-core:3.11.2'
    }

    testImplementation 'org.springframework.boot:spring-boot-properties-migrator'
    testImplementation 'org.mockito:mockito-core'
}

The expected Mockito version in testImplementation configuration is 3.11.2, but I get 3.9.0. However, I can get 3.11.2 version by removing org.springframework.boot:spring-boot-properties-migrator dependency.

 

The bug can be fixed by changing this line: https://github.com/spring-projects/spring-boot/blob/092ac696869b92b1635b6035966b59417f944430/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/build.gradle#L10

... to this one:

    api(platform(project(path: ":spring-boot-project:spring-boot-dependencies")))

 

Let me explain why I think it makes sense to change the current behavior.

  1. spring-boot-properties-migrator module depends on spring-boot-configuration-metadata: https://github.com/spring-projects/spring-boot/blob/60e57f7a3f8e3e92fb1d5b413b892d981e9e40fb/spring-boot-project/spring-boot-properties-migrator/build.gradle#L11

  2. spring-boot-configuration-metadata module depends on spring-boot-parent platform: https://github.com/spring-projects/spring-boot/blob/092ac696869b92b1635b6035966b59417f944430/spring-boot-project/spring-boot-tools/spring-boot-configuration-metadata/build.gradle#L10

  3. spring-boot-parent platform depends on spring-boot-dependencies enforced platform: https://github.com/spring-projects/spring-boot/blob/092ac696869b92b1635b6035966b59417f944430/spring-boot-project/spring-boot-parent/build.gradle#L176

  4. Enforcing spring-boot-dependencies platform makes Gradle prioritize its versions over versions defined in dependencies.constraints { ... }, even if the version in constraints is greater than the version in spring-boot-dependencies.

By making spring-boot-configuration-metadata depend on spring-boot-dependencies instead of spring-boot-parent we'll make Spring versions not enforced, and this will allow changing dependency versions in constraints.

Comment From: remal

For those who's faced this issue: you can fix it by using dependency substitution:

dependencies {
    modules {
        module('org.springframework.boot:spring-boot-parent') {
            replacedBy('org.springframework.boot:spring-boot-dependencies', 'org.springframework.boot:spring-boot-parent enforces versions')
        }
    }
}