Skip to content

Commit 4bf048c

Browse files
committed
Configure ByteBuddy agent on test tasks
This commit replaces the Mockito agent configuration with a single bytebuddy agent configuration that addresses both Mockito and mockk on tests. Closes gh-35207
1 parent ebe1f65 commit 4bf048c

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

buildSrc/src/main/java/org/springframework/build/TestConventions.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions;
2626
import org.gradle.testretry.TestRetryPlugin;
2727
import org.gradle.testretry.TestRetryTaskExtension;
28-
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest;
2928

3029
import java.util.Map;
3130

@@ -36,7 +35,7 @@
3635
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests
3736
* are retried 3 times when running on the CI server.
3837
* <li>Common test properties are configured
39-
* <li>The Mockito Java agent is set on test tasks.
38+
* <li>The ByteBuddy Java agent is configured on test tasks.
4039
* </ul>
4140
*
4241
* @author Brian Clozel
@@ -50,7 +49,7 @@ void apply(Project project) {
5049
}
5150

5251
private void configureTestConventions(Project project) {
53-
configureMockitoAgent(project);
52+
configureByteBuddyAgent(project);
5453
project.getTasks().withType(Test.class,
5554
test -> {
5655
configureTests(project, test);
@@ -81,20 +80,16 @@ private void configureTests(Project project, Test test) {
8180
);
8281
}
8382

84-
private void configureMockitoAgent(Project project) {
85-
if (project.hasProperty("mockitoVersion")) {
86-
String mockitoVersion = (String) project.getProperties().get("mockitoVersion");
87-
Configuration mockitoAgentConfig = project.getConfigurations().create("mockitoAgent");
88-
mockitoAgentConfig.setTransitive(false);
89-
Dependency mockitoCore = project.getDependencies().create("org.mockito:mockito-core:" + mockitoVersion);
90-
mockitoAgentConfig.getDependencies().add(mockitoCore);
83+
private void configureByteBuddyAgent(Project project) {
84+
if (project.hasProperty("byteBuddyVersion")) {
85+
String byteBuddyVersion = (String) project.getProperties().get("byteBuddyVersion");
86+
Configuration byteBuddyAgentConfig = project.getConfigurations().create("byteBuddyAgentConfig");
87+
byteBuddyAgentConfig.setTransitive(false);
88+
Dependency byteBuddyAgent = project.getDependencies().create("net.bytebuddy:byte-buddy-agent:" + byteBuddyVersion);
89+
byteBuddyAgentConfig.getDependencies().add(byteBuddyAgent);
9190
project.afterEvaluate(p -> {
92-
p.getTasks().withType(Test.class, test -> test.jvmArgs("-javaagent:" + mockitoAgentConfig.getAsPath()));
93-
project.getPlugins().withId("org.jetbrains.kotlin.jvm", plugin -> {
94-
project.getTasks().withType(KotlinJvmTest.class, kotlinTest -> {
95-
kotlinTest.jvmArgs("-javaagent:" + mockitoAgentConfig.getAsPath());
96-
});
97-
});
91+
p.getTasks().withType(Test.class, test -> test
92+
.jvmArgs("-javaagent:" + byteBuddyAgentConfig.getAsPath()));
9893
});
9994
}
10095
}

framework-platform/framework-platform.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020
api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.10.2"))
2121
api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.9.0"))
2222
api(platform("org.junit:junit-bom:5.13.3"))
23-
api(platform("org.mockito:mockito-bom:${mockitoVersion}"))
23+
api(platform("org.mockito:mockito-bom:5.18.0"))
2424
api(platform("tools.jackson:jackson-bom:3.0.0-rc5"))
2525

2626
constraints {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2048m
55
org.gradle.parallel=true
66

77
kotlinVersion=2.2.0
8-
mockitoVersion=5.18.0
8+
byteBuddyVersion=1.17.6
99

1010
kotlin.jvm.target.validation.mode=ignore
1111
kotlin.stdlib.default.dependency=false

0 commit comments

Comments
 (0)