Springb Boot 4.x Testing: import of TestRestTemplate cannot be resolved, JUnit 6, Gradle, Intellij
15:28 04 Mar 2026

I am having issues with the resolution of (for example)

import org.springframework.boot.test.web.client.TestRestTemplate;

Here below my build.gradle.kts with the dependencies management:

plugins {
    java
    alias(libs.plugins.springBoot)
    alias(libs.plugins.springDependencyMngmnt)
    id("idea")
}

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

dependencies {

    implementation(project(":prog1"))
    implementation(project(":prog2"))

    implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-security")

    compileOnly("org.projectlombok:lombok")
    annotationProcessor("org.projectlombok:lombok")

    developmentOnly("org.springframework.boot:spring-boot-devtools")


    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation(platform("org.testcontainers:testcontainers-bom:2.0.3"))
    testImplementation("org.testcontainers:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}

Versions are configured in the lib.versions.toml:

[versions]
junitJupiter = "6.0.1"
junitPlatformLauncher = "6.0.1"
springBoot = "4.0.0"
springDependencyMngmnt = "1.1.7"

[libraries]
junitJupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junitJupiter" }
junitPlatformLauncher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junitPlatformLauncher" }

[plugins]
springBoot = { id = "org.springframework.boot", version.ref = "springBoot"}
springDependencyMngmnt = { id = "io.spring.dependency-management", version.ref = "springDependencyMngmnt"}

A searched over and over and the dependencies configuration looks fine to me, but eventually it isn't because the classes are not properly resolved in test class. For what concerns the application, it runs without any problem; only the tests are problematic.

Can somebody point out where the problem / conflict may be located?

spring-boot