Files
spring-boot/system-test/spring-boot-deployment-system-tests/build.gradle
T
Andy Wilkinson 3e82ede609 Require spring-boot-restclient dependency to use TestRestTemplate
Previously, spring-boot-restclient was a required dependency of
spring-boot-resttestclient. This had the unwanted side-effect of
increasing the risk of the test classpath enabling auto-configuration
for RestClient.Builder when it was main code that needed such a bean.
This could lead to integration tests passing but the application
itself failing to start when its run through its main method.

This commit makes spring-boot-restclient an optional dependency of
spring-boot-resttestclient. As a result, a dependency on
spring-boot-resttestclient is no longer sufficient to auto-configure
a RestClient.Builder bean, although it is still sufficient to
auto-configure a RestTestClient bean.

Those that wish to use TestRestTemplate rather than migrating to
RestTestClient will now have to add a dependency on
spring-boot-restclient. This makes it presence more obvious. It now
has to be declared directly rather than being somewhat hidden due to
being pulled in transitively. The hope is that this will reduce the
chances of the dependency being accidentially on the test classpath
when main code requires it to be on the runtime classpath.

Fixes gh-48253
2025-11-25 14:38:33 +00:00

69 lines
2.1 KiB
Groovy

/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "war"
id "org.springframework.boot.system-test"
}
description = "Spring Boot Deployment Tests"
configurations {
providedRuntime {
extendsFrom dependencyManagement
}
}
configurations.all {
exclude module: "spring-boot-starter-logging"
}
dependencies {
compileOnly("jakarta.servlet:jakarta.servlet-api")
implementation(project(":starter:spring-boot-starter-webmvc")) {
exclude group: "org.hibernate.validator"
exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
}
implementation(project(":starter:spring-boot-starter-actuator"))
systemTestImplementation(enforcedPlatform(project(path: ":platform:spring-boot-internal-dependencies")))
systemTestImplementation(project(":module:spring-boot-restclient"))
systemTestImplementation(project(":module:spring-boot-resttestclient"))
systemTestImplementation(project(":starter:spring-boot-starter-test"))
systemTestImplementation(project(":test-support:spring-boot-test-support"))
systemTestImplementation("org.apache.httpcomponents.client5:httpclient5")
systemTestImplementation("org.slf4j:slf4j-simple")
systemTestImplementation("org.springframework:spring-web")
systemTestImplementation("org.testcontainers:testcontainers-junit-jupiter")
}
systemTest {
inputs.files(war).withNormalizer(ClasspathNormalizer).withPropertyName("war")
}
war {
archiveVersion = ''
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
tasks.named("compileSystemTestJava") {
options.nullability.checking = "tests"
}