|
11 | 11 | import org.gradle.api.Action; |
12 | 12 | import org.gradle.api.Describable; |
13 | 13 | import org.gradle.api.Project; |
| 14 | +import org.gradle.api.artifacts.Configuration; |
14 | 15 | import org.gradle.api.artifacts.ConfigurationContainer; |
15 | 16 | import org.gradle.api.artifacts.dsl.DependencyHandler; |
16 | 17 | import org.gradle.api.file.RegularFile; |
@@ -61,6 +62,7 @@ public JavaModuleTestingExtension(Project project) { |
61 | 62 | whitebox(jvmTestSuite, conf -> conf.getOpensTo().add("org.junit.platform.commons")); |
62 | 63 | } |
63 | 64 | }); |
| 65 | + project.afterEvaluate(this::lateConfigureExtendsFrom); |
64 | 66 | } |
65 | 67 |
|
66 | 68 | /** |
@@ -281,12 +283,10 @@ private void configureJvmTestSuiteForWhitebox( |
281 | 283 |
|
282 | 284 | addDependencyForRequires( |
283 | 285 | whiteboxJvmTestSuite, |
284 | | - project, |
285 | 286 | testSources.getImplementationConfigurationName(), |
286 | 287 | whiteboxJvmTestSuite.getRequires()); |
287 | 288 | addDependencyForRequires( |
288 | 289 | whiteboxJvmTestSuite, |
289 | | - project, |
290 | 290 | testSources.getRuntimeOnlyConfigurationName(), |
291 | 291 | whiteboxJvmTestSuite.getRequiresRuntime()); |
292 | 292 | } |
@@ -360,4 +360,30 @@ private void revertJvmTestSuiteForWhitebox(JvmTestSuite jvmTestSuite) { |
360 | 360 | test.getJvmArgumentProviders().removeIf(p -> p instanceof WhiteboxTestRuntimeArgumentProvider); |
361 | 361 | }); |
362 | 362 | } |
| 363 | + |
| 364 | + private void lateConfigureExtendsFrom(Project project) { |
| 365 | + ConfigurationContainer configurations = project.getConfigurations(); |
| 366 | + whiteboxOrClasspathTestSuites.forEach((testSources, sourcesUnderTest) -> { |
| 367 | + extendsFrom( |
| 368 | + configurations, |
| 369 | + testSources.getImplementationConfigurationName(), |
| 370 | + sourcesUnderTest.getImplementationConfigurationName()); |
| 371 | + extendsFrom( |
| 372 | + configurations, |
| 373 | + testSources.getRuntimeOnlyConfigurationName(), |
| 374 | + sourcesUnderTest.getRuntimeOnlyConfigurationName()); |
| 375 | + extendsFrom( |
| 376 | + configurations, |
| 377 | + testSources.getCompileOnlyConfigurationName(), |
| 378 | + sourcesUnderTest.getCompileOnlyConfigurationName()); |
| 379 | + }); |
| 380 | + } |
| 381 | + |
| 382 | + private void extendsFrom(ConfigurationContainer configurations, String testScope, String underTestScope) { |
| 383 | + Configuration testScopeConf = configurations.getByName(testScope); |
| 384 | + Configuration underTestScopeConf = configurations.getByName(underTestScope); |
| 385 | + if (!testScopeConf.getExtendsFrom().contains(underTestScopeConf)) { |
| 386 | + testScopeConf.extendsFrom(underTestScopeConf); |
| 387 | + } |
| 388 | + } |
363 | 389 | } |
0 commit comments