Skip to content

Dependency Resolution

Immortius edited this page May 29, 2015 · 2 revisions

Dependency Resolution

gestalt-module provides a DependencyResolver that will determine a compatible set of modules, given a list of the ids of required modules and a ModuleRegistry populated with available modules.

DependencyResolver resolver = new DependencyResolver(registry);
ResolutionResult resolutionResult = resolver.resolve(new Name("ModuleOne"), new Name("ModuleTwo"));
if (resolutionResult.isSuccess()) {
    resolutionResult.getModules();
}

Dependency Resolution follows these rules:

  • All requested modules must be present and all dependencies satisfied, or else the resolution is considered a failure.
  • If multiple possible versions of a module are possible, the latest version is picked and other versions discarded. This is done first for the required modules, in the order specified, before proceeding though their dependencies. This is notable because using the latest version of a module may disqualify the latest version of other modules.

At the moment the DependencyResolver does not report a reason for failure - this is difficult to pinpoint in the general case due multiple versions and different versions having different dependencies.

For optional dependencies, an OptionalResolutionStrategy is used to determine how to handle them. The three possibilities are:

  • INCLUDE_IF_REQUIRED: This is the default strategy. An optional dependency to a module will only be included if it is required by another module. If it is required then it must conform to the version range of the optional dependency.
  • INCLUDE_IF_AVAILABLE: An optional dependency to a module will be included if is available and conforms to the version range of the dependency, but if it is not available resolution will not fail.
  • FORCE_INCLUDE: Optional dependencies are treated as mandatory dependencies.