|
19 | 19 | import java.io.File; |
20 | 20 | import java.util.ArrayList; |
21 | 21 | import java.util.Arrays; |
| 22 | +import java.util.Collection; |
22 | 23 | import java.util.Collections; |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.HashSet; |
|
27 | 28 | import java.util.Map; |
28 | 29 | import java.util.Set; |
29 | 30 | import java.util.TreeMap; |
| 31 | +import java.util.concurrent.TimeUnit; |
30 | 32 | import java.util.function.Function; |
31 | 33 | import java.util.regex.Matcher; |
32 | 34 | import java.util.regex.Pattern; |
@@ -428,6 +430,13 @@ public interface VersionAlignment { |
428 | 430 |
|
429 | 431 | Set<String> resolve(); |
430 | 432 |
|
| 433 | + default Configuration alignmentConfiguration(Project project, Collection<Dependency> dependencies) { |
| 434 | + Configuration alignmentConfiguration = project.getConfigurations() |
| 435 | + .detachedConfiguration(dependencies.toArray(new Dependency[0])); |
| 436 | + alignmentConfiguration.getResolutionStrategy().cacheChangingModulesFor(0, TimeUnit.SECONDS); |
| 437 | + return alignmentConfiguration; |
| 438 | + } |
| 439 | + |
431 | 440 | } |
432 | 441 |
|
433 | 442 | /** |
@@ -492,8 +501,7 @@ public Set<String> resolve() { |
492 | 501 |
|
493 | 502 | private Map<String, String> resolveAligningDependencies() { |
494 | 503 | List<Dependency> dependencies = getAligningDependencies(); |
495 | | - Configuration alignmentConfiguration = this.project.getConfigurations() |
496 | | - .detachedConfiguration(dependencies.toArray(new Dependency[0])); |
| 504 | + Configuration alignmentConfiguration = alignmentConfiguration(this.project, dependencies); |
497 | 505 | Map<String, String> versions = new HashMap<>(); |
498 | 506 | ResolutionResult resolutionResult = alignmentConfiguration.getIncoming().getResolutionResult(); |
499 | 507 | for (DependencyResult dependency : resolutionResult.getAllDependencies()) { |
@@ -605,8 +613,7 @@ public Set<String> resolve() { |
605 | 613 | if (this.alignedVersions != null) { |
606 | 614 | return this.alignedVersions; |
607 | 615 | } |
608 | | - Configuration alignmentConfiguration = this.project.getConfigurations() |
609 | | - .detachedConfiguration(getAligningDependencies().toArray(new Dependency[0])); |
| 616 | + Configuration alignmentConfiguration = alignmentConfiguration(this.project, getAligningDependencies()); |
610 | 617 | Set<File> files = alignmentConfiguration.resolve(); |
611 | 618 | if (files.size() != 1) { |
612 | 619 | throw new IllegalStateException( |
|
0 commit comments