Resolution order of forcedModules

(DC) #1


If we have a list of forcedModules and then append to the list using force will the last added dependencies have higher resolution priority?
e.g. if we had something like contrived example below

configurations.all {
  resolutionStrategy {
    forcedModules = ['foo:foo:2.0.0', 'bar:bar:2.0.0']
    force 'foo:foo:1.0.0'

Can we be sure the foo:foo:1.0.0 version would be used over the 2.0.0 version? I do this this happening in my use case but I would like confirmation that we are guaranteed that this will happen, that is the most recently appended module will take priority.


(DC) #2

Internally within Gradle the dependencies in the forcedModules collection are added (put) to a map in order they appear. This means the order dependencies are added to the forcedModules collection is important, dependencies added after a previous instance of that dependency are over written in the internal HashMap. Below is a code extract of the
> public class ModuleForcingResolveRule implements Action {
> private final Map<ModuleIdentifier, String> forcedModules;
> public ModuleForcingResolveRule(Collection<? extends ModuleVersionSelector> forcedModules) {
> if (!forcedModules.isEmpty()) {
> this.forcedModules = new HashMap<ModuleIdentifier, String>();
> for (ModuleVersionSelector module : forcedModules) {
> this.forcedModules.put(new DefaultModuleIdentifier(module.getGroup(), module.getName()), module.getVersion());
> }
> } else {
> this.forcedModules = null;
> }
> }

This is internal so i guess it could change at a later date.