How to override the version comparison mechanism?

Ah, I thought you had a dependency conflict but you are referring to dynamic dependencies. I think this can be done via a ComponentSelectionRule

resolutionStrategy {
   componentSelection {
      Comparator<ComponentSelection> comparator = new MyFantasticVersionComparator()
      Map<String, Set<ComponentSelection>> grouped = [:]
      all { ComponentSelection selection ->
         String key = "${selection.candidate.group}:${selection.candidate.name}"
         def set = grouped[key]
         if (!set) {
            set = new TreeSet(comparator)
            grouped[key] = set
         }
         set<< selection
      }
      for (Set set : grouped.values()) {
         Iterator<ComponentSelection> iterator = set.iterator()
         for (int i = 0; i < set.size() - 1) {
            iterator.next().reject("Better version available")
         }
      }
   }
}
2 Likes