Skip to content

Commit e12bb7b

Browse files
committed
Library upgrade policy should not reduce bom's policy
Library-specific upgrade policies were added to allow a dependency to have a less strict upgrade policy, for example so that a new minor upgrade could be applied in a maintenance release. As currently implemented, a library-specific policy that's more restrictive than the bom's policy may result in a possibl upgrade being missed. This commit updates the library-specific support to use the maximum (most permissive) upgrade policy so that possible upgrades are not hidden by a less permissive library-specific policy. See gh-46369
1 parent 4babe2e commit e12bb7b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@ public boolean test(DependencyVersion candidate, DependencyVersion current) {
5353
return this.delegate.test(candidate, current);
5454
}
5555

56+
public static UpgradePolicy max(UpgradePolicy one, UpgradePolicy two) {
57+
if (one == null && two != null) {
58+
return two;
59+
}
60+
else if (one != null && two == null) {
61+
return one;
62+
}
63+
return (one.ordinal() < two.ordinal()) ? one : two;
64+
}
65+
5666
}

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,9 @@ protected BiFunction<Library, DependencyVersion, VersionOption> createVersionOpt
265265
}
266266

267267
private boolean compliesWithUpgradePolicy(Library library, DependencyVersion candidate) {
268-
UpgradePolicy upgradePolicy = library.getUpgradePolicy();
269-
if (upgradePolicy == null) {
270-
upgradePolicy = this.bom.getUpgrade().getPolicy();
271-
}
268+
UpgradePolicy libraryPolicy = library.getUpgradePolicy();
269+
UpgradePolicy bomPolicy = this.bom.getUpgrade().getPolicy();
270+
UpgradePolicy upgradePolicy = UpgradePolicy.max(libraryPolicy, bomPolicy);
272271
return upgradePolicy.test(candidate, library.getVersion().getVersion());
273272
}
274273

0 commit comments

Comments
 (0)