16
16
17
17
package org .springframework .build ;
18
18
19
- import java .util .Map ;
20
-
21
19
import org .gradle .api .Project ;
20
+ import org .gradle .api .artifacts .Configuration ;
21
+ import org .gradle .api .artifacts .Dependency ;
22
22
import org .gradle .api .plugins .JavaBasePlugin ;
23
23
import org .gradle .api .tasks .testing .Test ;
24
24
import org .gradle .api .tasks .testing .TestFrameworkOptions ;
25
25
import org .gradle .api .tasks .testing .junitplatform .JUnitPlatformOptions ;
26
26
import org .gradle .testretry .TestRetryPlugin ;
27
27
import org .gradle .testretry .TestRetryTaskExtension ;
28
28
29
+ import java .util .Map ;
30
+
29
31
/**
30
32
* Conventions that are applied in the presence of the {@link JavaBasePlugin}. When the
31
33
* plugin is applied:
32
34
* <ul>
33
35
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests
34
36
* are retried 3 times when running on the CI server.
37
+ * <li>Common test properties are configured
38
+ * <li>The Mockito Java agent is set on test tasks.
35
39
* </ul>
36
40
*
37
41
* @author Brian Clozel
@@ -45,6 +49,7 @@ void apply(Project project) {
45
49
}
46
50
47
51
private void configureTestConventions (Project project ) {
52
+ configureMockitoAgent (project );
48
53
project .getTasks ().withType (Test .class ,
49
54
test -> {
50
55
configureTests (project , test );
@@ -75,6 +80,19 @@ private void configureTests(Project project, Test test) {
75
80
);
76
81
}
77
82
83
+ private void configureMockitoAgent (Project project ) {
84
+ if (project .hasProperty ("mockitoVersion" )) {
85
+ String mockitoVersion = (String ) project .getProperties ().get ("mockitoVersion" );
86
+ Configuration mockitoAgentConfig = project .getConfigurations ().create ("mockitoAgent" );
87
+ mockitoAgentConfig .setTransitive (false );
88
+ Dependency mockitoCore = project .getDependencies ().create ("org.mockito:mockito-core:" + mockitoVersion );
89
+ mockitoAgentConfig .getDependencies ().add (mockitoCore );
90
+ project .afterEvaluate (p -> {
91
+ p .getTasks ().withType (Test .class , test -> test .jvmArgs ("-javaagent:" + mockitoAgentConfig .getAsPath ()));
92
+ });
93
+ }
94
+ }
95
+
78
96
private void configureTestRetryPlugin (Project project , Test test ) {
79
97
project .getPlugins ().withType (TestRetryPlugin .class , testRetryPlugin -> {
80
98
TestRetryTaskExtension testRetry = test .getExtensions ().getByType (TestRetryTaskExtension .class );
0 commit comments