|
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.function.Predicate; |
32 | 34 | import java.util.regex.Matcher; |
@@ -429,6 +431,13 @@ public interface VersionAlignment { |
429 | 431 |
|
430 | 432 | Set<String> resolve(); |
431 | 433 |
|
| 434 | + default Configuration alignmentConfiguration(Project project, Collection<Dependency> dependencies) { |
| 435 | + Configuration alignmentConfiguration = project.getConfigurations() |
| 436 | + .detachedConfiguration(dependencies.toArray(new Dependency[0])); |
| 437 | + alignmentConfiguration.getResolutionStrategy().cacheChangingModulesFor(0, TimeUnit.SECONDS); |
| 438 | + return alignmentConfiguration; |
| 439 | + } |
| 440 | + |
432 | 441 | } |
433 | 442 |
|
434 | 443 | public static class BomAlignment { |
@@ -514,8 +523,7 @@ public Set<String> resolve() { |
514 | 523 |
|
515 | 524 | private Map<String, String> resolveAligningDependencies() { |
516 | 525 | List<Dependency> dependencies = getAligningDependencies(); |
517 | | - Configuration alignmentConfiguration = this.project.getConfigurations() |
518 | | - .detachedConfiguration(dependencies.toArray(new Dependency[0])); |
| 526 | + Configuration alignmentConfiguration = alignmentConfiguration(this.project, dependencies); |
519 | 527 | Map<String, String> versions = new HashMap<>(); |
520 | 528 | ResolutionResult resolutionResult = alignmentConfiguration.getIncoming().getResolutionResult(); |
521 | 529 | for (DependencyResult dependency : resolutionResult.getAllDependencies()) { |
@@ -627,8 +635,7 @@ public Set<String> resolve() { |
627 | 635 | if (this.alignedVersions != null) { |
628 | 636 | return this.alignedVersions; |
629 | 637 | } |
630 | | - Configuration alignmentConfiguration = this.project.getConfigurations() |
631 | | - .detachedConfiguration(getAligningDependencies().toArray(new Dependency[0])); |
| 638 | + Configuration alignmentConfiguration = alignmentConfiguration(this.project, getAligningDependencies()); |
632 | 639 | Set<File> files = alignmentConfiguration.resolve(); |
633 | 640 | if (files.size() != 1) { |
634 | 641 | throw new IllegalStateException( |
|
0 commit comments