mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Configure Mockito Java agent in Test tasks
Closes gh-35207
This commit is contained in:
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.build;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.plugins.JavaBasePlugin;
|
||||
import org.gradle.api.tasks.testing.Test;
|
||||
import org.gradle.api.tasks.testing.TestFrameworkOptions;
|
||||
@@ -26,12 +26,16 @@ import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions;
|
||||
import org.gradle.testretry.TestRetryPlugin;
|
||||
import org.gradle.testretry.TestRetryTaskExtension;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Conventions that are applied in the presence of the {@link JavaBasePlugin}. When the
|
||||
* plugin is applied:
|
||||
* <ul>
|
||||
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests
|
||||
* are retried 3 times when running on the CI server.
|
||||
* <li>Common test properties are configured
|
||||
* <li>The Mockito Java agent is set on test tasks.
|
||||
* </ul>
|
||||
*
|
||||
* @author Brian Clozel
|
||||
@@ -45,6 +49,7 @@ class TestConventions {
|
||||
}
|
||||
|
||||
private void configureTestConventions(Project project) {
|
||||
configureMockitoAgent(project);
|
||||
project.getTasks().withType(Test.class,
|
||||
test -> {
|
||||
configureTests(project, test);
|
||||
@@ -75,6 +80,19 @@ class TestConventions {
|
||||
);
|
||||
}
|
||||
|
||||
private void configureMockitoAgent(Project project) {
|
||||
if (project.hasProperty("mockitoVersion")) {
|
||||
String mockitoVersion = (String) project.getProperties().get("mockitoVersion");
|
||||
Configuration mockitoAgentConfig = project.getConfigurations().create("mockitoAgent");
|
||||
mockitoAgentConfig.setTransitive(false);
|
||||
Dependency mockitoCore = project.getDependencies().create("org.mockito:mockito-core:" + mockitoVersion);
|
||||
mockitoAgentConfig.getDependencies().add(mockitoCore);
|
||||
project.afterEvaluate(p -> {
|
||||
p.getTasks().withType(Test.class, test -> test.jvmArgs("-javaagent:" + mockitoAgentConfig.getAsPath()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void configureTestRetryPlugin(Project project, Test test) {
|
||||
project.getPlugins().withType(TestRetryPlugin.class, testRetryPlugin -> {
|
||||
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
|
||||
|
||||
@@ -20,7 +20,7 @@ dependencies {
|
||||
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.junit:junit-bom:5.13.3"))
|
||||
api(platform("org.mockito:mockito-bom:5.18.0"))
|
||||
api(platform("org.mockito:mockito-bom:${mockitoVersion}"))
|
||||
api(platform("tools.jackson:jackson-bom:3.0.0-rc5"))
|
||||
|
||||
constraints {
|
||||
|
||||
@@ -5,6 +5,7 @@ org.gradle.jvmargs=-Xmx2048m
|
||||
org.gradle.parallel=true
|
||||
|
||||
kotlinVersion=2.2.0
|
||||
mockitoVersion=5.18.0
|
||||
|
||||
kotlin.jvm.target.validation.mode=ignore
|
||||
kotlin.stdlib.default.dependency=false
|
||||
|
||||
Reference in New Issue
Block a user