Browse Source

updateDependencies support custom rules

Issue gh-9542
Rob Winch 4 years ago
parent
commit
eb6dccf05d

+ 12 - 0
buildSrc/src/main/java/org/springframework/security/convention/versions/UpdateDependenciesExtension.java

@@ -1,6 +1,8 @@
 package org.springframework.security.convention.versions;
 
+import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionRulesWithCurrent;
 import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent;
+import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ResolutionStrategyWithCurrent;
 import org.gradle.api.Action;
 
 import java.io.File;
@@ -115,11 +117,16 @@ public class UpdateDependenciesExtension {
 	 */
 	public class DependencyExcludes {
 		private List<Action<ComponentSelectionWithCurrent>> actions = new ArrayList<>();
+		private List<Action<ComponentSelectionRulesWithCurrent>> components = new ArrayList<>();
 
 		List<Action<ComponentSelectionWithCurrent>> getActions() {
 			return actions;
 		}
 
+		public List<Action<ComponentSelectionRulesWithCurrent>> getComponents() {
+			return components;
+		}
+
 		public DependencyExcludes alphaBetaVersions() {
 			this.actions.add(excludeVersionWithRegex("(?i).*?(alpha|beta).*", "an alpha or beta version"));
 			return this;
@@ -155,6 +162,11 @@ public class UpdateDependenciesExtension {
 			return this;
 		}
 
+		public DependencyExcludes addRule(Action<ComponentSelectionRulesWithCurrent> rule) {
+			this.components.add(rule);
+			return this;
+		}
+
 		private Action<ComponentSelectionWithCurrent> excludeVersionWithRegex(String regex, String reason) {
 			Pattern pattern = Pattern.compile(regex);
 			return (selection) -> {

+ 3 - 0
buildSrc/src/main/java/org/springframework/security/convention/versions/UpdateDependenciesPlugin.java

@@ -68,6 +68,9 @@ public class UpdateDependenciesPlugin implements Plugin<Project> {
 								updateDependenciesSettings.getExcludes().getActions().forEach((action) -> {
 									components.all(action);
 								});
+								updateDependenciesSettings.getExcludes().getComponents().forEach((action) -> {
+									action.execute(components);
+								});
 								components.all((selection) -> {
 									ModuleComponentIdentifier candidate = selection.getCandidate();
 									if (candidate.getGroup().startsWith("org.apache.directory.") && !candidate.getVersion().equals(selection.getCurrentVersion())) {