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
This commit is contained in:
parent
ebe1f65e21
commit
4bf048cfcf
|
@ -25,7 +25,6 @@ import org.gradle.api.tasks.testing.TestFrameworkOptions;
|
||||||
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions;
|
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions;
|
||||||
import org.gradle.testretry.TestRetryPlugin;
|
import org.gradle.testretry.TestRetryPlugin;
|
||||||
import org.gradle.testretry.TestRetryTaskExtension;
|
import org.gradle.testretry.TestRetryTaskExtension;
|
||||||
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ import java.util.Map;
|
||||||
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests
|
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests
|
||||||
* are retried 3 times when running on the CI server.
|
* are retried 3 times when running on the CI server.
|
||||||
* <li>Common test properties are configured
|
* <li>Common test properties are configured
|
||||||
* <li>The Mockito Java agent is set on test tasks.
|
* <li>The ByteBuddy Java agent is configured on test tasks.
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
@ -50,7 +49,7 @@ class TestConventions {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureTestConventions(Project project) {
|
private void configureTestConventions(Project project) {
|
||||||
configureMockitoAgent(project);
|
configureByteBuddyAgent(project);
|
||||||
project.getTasks().withType(Test.class,
|
project.getTasks().withType(Test.class,
|
||||||
test -> {
|
test -> {
|
||||||
configureTests(project, test);
|
configureTests(project, test);
|
||||||
|
@ -81,20 +80,16 @@ class TestConventions {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureMockitoAgent(Project project) {
|
private void configureByteBuddyAgent(Project project) {
|
||||||
if (project.hasProperty("mockitoVersion")) {
|
if (project.hasProperty("byteBuddyVersion")) {
|
||||||
String mockitoVersion = (String) project.getProperties().get("mockitoVersion");
|
String byteBuddyVersion = (String) project.getProperties().get("byteBuddyVersion");
|
||||||
Configuration mockitoAgentConfig = project.getConfigurations().create("mockitoAgent");
|
Configuration byteBuddyAgentConfig = project.getConfigurations().create("byteBuddyAgentConfig");
|
||||||
mockitoAgentConfig.setTransitive(false);
|
byteBuddyAgentConfig.setTransitive(false);
|
||||||
Dependency mockitoCore = project.getDependencies().create("org.mockito:mockito-core:" + mockitoVersion);
|
Dependency byteBuddyAgent = project.getDependencies().create("net.bytebuddy:byte-buddy-agent:" + byteBuddyVersion);
|
||||||
mockitoAgentConfig.getDependencies().add(mockitoCore);
|
byteBuddyAgentConfig.getDependencies().add(byteBuddyAgent);
|
||||||
project.afterEvaluate(p -> {
|
project.afterEvaluate(p -> {
|
||||||
p.getTasks().withType(Test.class, test -> test.jvmArgs("-javaagent:" + mockitoAgentConfig.getAsPath()));
|
p.getTasks().withType(Test.class, test -> test
|
||||||
project.getPlugins().withId("org.jetbrains.kotlin.jvm", plugin -> {
|
.jvmArgs("-javaagent:" + byteBuddyAgentConfig.getAsPath()));
|
||||||
project.getTasks().withType(KotlinJvmTest.class, kotlinTest -> {
|
|
||||||
kotlinTest.jvmArgs("-javaagent:" + mockitoAgentConfig.getAsPath());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ dependencies {
|
||||||
api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.10.2"))
|
api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.10.2"))
|
||||||
api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.9.0"))
|
api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.9.0"))
|
||||||
api(platform("org.junit:junit-bom:5.13.3"))
|
api(platform("org.junit:junit-bom:5.13.3"))
|
||||||
api(platform("org.mockito:mockito-bom:${mockitoVersion}"))
|
api(platform("org.mockito:mockito-bom:5.18.0"))
|
||||||
api(platform("tools.jackson:jackson-bom:3.0.0-rc5"))
|
api(platform("tools.jackson:jackson-bom:3.0.0-rc5"))
|
||||||
|
|
||||||
constraints {
|
constraints {
|
||||||
|
|
|
@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2048m
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
kotlinVersion=2.2.0
|
kotlinVersion=2.2.0
|
||||||
mockitoVersion=5.18.0
|
byteBuddyVersion=1.17.6
|
||||||
|
|
||||||
kotlin.jvm.target.validation.mode=ignore
|
kotlin.jvm.target.validation.mode=ignore
|
||||||
kotlin.stdlib.default.dependency=false
|
kotlin.stdlib.default.dependency=false
|
||||||
|
|
Loading…
Reference in New Issue