Skip to content

Commit 86818b0

Browse files
committed
Ensure that junit-platform-launcher is on classpath
When testing with Gradle 7.6, junit-platform-launcher won't be on the test runtime classpath unless it's declared as a dependency. When testing with Gradle 8.x the dependency is added implicitly but starting with Gradle 8.3 relying on this will result in a warning. When junit-platform-launcher is absent, a failure occurs when testing with Gradle as the class loader structure is such that JUnit tries to load any test execution listeners, finds the listener declared in spring-boot-actuator-autoconfigure but cannot then load the implemented TestExecutionListener interface. This problem is addressed by augmenting the component metadata for spring-boot-starter-test to add a dependency on junit-platform-launcher. This addresses the problem with spring-boot-actuator-autoconfigure while also addressing a warning with Gradle 8.3+. Closes gh-43340
1 parent 1081192 commit 86818b0

File tree

1 file changed

+11
-1
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin

1 file changed

+11
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,6 +89,7 @@ public void execute(Project project) {
8989
project.afterEvaluate(this::configureUtf8Encoding);
9090
configureParametersCompilerArg(project);
9191
configureAdditionalMetadataLocations(project);
92+
configureSpringBootStarterTestToDependOnJUnitPlatformLauncher(project);
9293
}
9394

9495
private void classifyJarTask(Project project) {
@@ -317,6 +318,15 @@ private void configureTestAndDevelopmentOnlyConfiguration(Project project) {
317318
testImplementation.extendsFrom(testAndDevelopmentOnly);
318319
}
319320

321+
private void configureSpringBootStarterTestToDependOnJUnitPlatformLauncher(Project project) {
322+
project.getDependencies()
323+
.components((components) -> components.withModule("org.springframework.boot:spring-boot-starter-test",
324+
(metadata) -> metadata.withVariant("runtimeElements", (variant) -> variant.withDependencies(
325+
(dependencies) -> dependencies.add("org.junit.platform:junit-platform-launcher")
326+
327+
))));
328+
}
329+
320330
/**
321331
* Task {@link Action} to add additional meta-data locations. We need to use an
322332
* inner-class rather than a lambda due to

0 commit comments

Comments
 (0)