- java.lang.Object
- 
- java.lang.module.Configuration
 
- 
 public final class Configuration extends Object A configuration that is the result of resolution or resolution with service binding.A configuration encapsulates the readability graph that is the output of resolution. A readability graph is a directed graph whose vertices are of type ResolvedModuleand the edges represent the readability amongst the modules.Configurationdefines themodules()method to get the set of resolved modules in the graph.ResolvedModuledefines thereads()method to get the set of modules that a resolved module reads. The modules that are read may be in the same configuration or may be inparentconfigurations.Configuration defines the resolvemethod to resolve a collection of root modules, and theresolveAndBindmethod to do resolution with service binding. There are instance and static variants of both methods. The instance methods create a configuration with the receiver as the parent configuration. The static methods are for more advanced cases where there can be more than one parent configuration.Each layerof modules in the Java virtual machine is created from a configuration. The configuration for thebootlayer is obtained by invokingModuleLayer.boot().configuration(). The configuration for the boot layer will often be the parent when creating new configurations.ExampleThe following example uses the resolvemethod to resolve a module named myapp with the configuration for the boot layer as the parent configuration. It prints the name of each resolved module and the names of the modules that each module reads.ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp")); cf.modules().forEach(m -> { System.out.format("%s -> %s%n", m.name(), m.reads().stream() .map(ResolvedModule::name) .collect(Collectors.joining(", "))); });- Since:
- 9
- See Also:
- ModuleLayer
 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Configurationempty()Returns the empty configuration.Optional<ResolvedModule>findModule(String name)Finds a resolved module in this configuration, or if not in this configuration, the parent configurations.Set<ResolvedModule>modules()Returns an immutable set of the resolved modules in this configuration.List<Configuration>parents()Returns an unmodifiable list of this configuration's parents, in search order.Configurationresolve(ModuleFinder before, ModuleFinder after, Collection<String> roots)Resolves a collection of root modules, with this configuration as its parent, to create a new configuration.static Configurationresolve(ModuleFinder before, List<Configuration> parents, ModuleFinder after, Collection<String> roots)Resolves a collection of root modules to create a configuration.ConfigurationresolveAndBind(ModuleFinder before, ModuleFinder after, Collection<String> roots)Resolves a collection of root modules, with service binding, and with this configuration as its parent, to create a new configuration.static ConfigurationresolveAndBind(ModuleFinder before, List<Configuration> parents, ModuleFinder after, Collection<String> roots)Resolves a collection of root modules, with service binding, to create configuration.StringtoString()Returns a string describing this configuration.
 
- 
- 
- 
Method Detail- 
resolvepublic Configuration resolve(ModuleFinder before, ModuleFinder after, Collection<String> roots) Resolves a collection of root modules, with this configuration as its parent, to create a new configuration. This method works exactly as specified by the staticresolvemethod when invoked with this configuration as the parent. In other words, if this configuration iscfthen this method is equivalent to invoking:Configuration.resolve(before, List.of(cf), after, roots);- Parameters:
- before- The before module finder to find modules
- after- The after module finder to locate modules when not located by the- beforemodule finder or in parent configurations
- roots- The possibly-empty collection of module names of the modules to resolve
- Returns:
- The configuration that is the result of resolving the given root modules
- Throws:
- FindException- If resolution fails for any of the observability-related reasons specified by the static- resolvemethod
- ResolutionException- If resolution fails any of the consistency checks specified by the static- resolvemethod
- SecurityException- If locating a module is denied by the security manager
 
 - 
resolveAndBindpublic Configuration resolveAndBind(ModuleFinder before, ModuleFinder after, Collection<String> roots) Resolves a collection of root modules, with service binding, and with this configuration as its parent, to create a new configuration. This method works exactly as specified by the staticresolveAndBindmethod when invoked with this configuration as the parent. In other words, if this configuration iscfthen this method is equivalent to invoking:Configuration.resolveAndBind(before, List.of(cf), after, roots);- Parameters:
- before- The before module finder to find modules
- after- The after module finder to locate modules when not located by the- beforemodule finder or in parent configurations
- roots- The possibly-empty collection of module names of the modules to resolve
- Returns:
- The configuration that is the result of resolving, with service binding, the given root modules
- Throws:
- FindException- If resolution fails for any of the observability-related reasons specified by the static- resolvemethod
- ResolutionException- If resolution fails any of the consistency checks specified by the static- resolvemethod
- SecurityException- If locating a module is denied by the security manager
 
 - 
resolvepublic static Configuration resolve(ModuleFinder before, List<Configuration> parents, ModuleFinder after, Collection<String> roots) Resolves a collection of root modules to create a configuration.Each root module is located using the given beforemodule finder. If a module is not found then it is located in the parent configuration as if by invoking thefindModulemethod on each parent in iteration order. If not found then the module is located using the givenaftermodule finder. The same search order is used to locate transitive dependences. Root modules or dependences that are located in a parent configuration are resolved no further and are not included in the resulting configuration.When all modules have been enumerated then a readability graph is computed, and in conjunction with the module exports and service use, checked for consistency. Resolution may fail with FindExceptionfor the following observability-related reasons:- A root module, or a direct or transitive dependency, is not found. 
- An error occurs when attempting to find a module. Possible errors include I/O errors, errors detected parsing a module descriptor ( - module-info.class) or two versions of the same module are found in the same directory.
 Resolution may fail with ResolutionExceptionif any of the following consistency checks fail:- A cycle is detected, say where module - m1requires module- m2and- m2requires- m1.
- A module reads two or more modules with the same name. This includes the case where a module reads another with the same name as itself. 
- Two or more modules in the configuration export the same package to a module that reads both. This includes the case where a module - Mcontaining package- preads another module that exports- pto- M.
- A module - Mdeclares that it "- uses p.S" or "- provides p.S with ..." but package- pis neither in module- Mnor exported to- Mby any module that- Mreads.
 - Implementation Note:
- In the implementation then observability of modules may depend on referential integrity or other checks that ensure different builds of tightly coupled modules or modules for specific operating systems or architectures are not combined in the same configuration.
- Parameters:
- before- The before module finder to find modules
- parents- The list parent configurations in search order
- after- The after module finder to locate modules when not located by the- beforemodule finder or in parent configurations
- roots- The possibly-empty collection of module names of the modules to resolve
- Returns:
- The configuration that is the result of resolving the given root modules
- Throws:
- FindException- If resolution fails for any of observability-related reasons specified above
- ResolutionException- If resolution fails for any of the consistency checks specified above
- IllegalArgumentException- If the list of parents is empty, or the list has two or more parents with modules for different target operating systems, architectures, or versions
- SecurityException- If locating a module is denied by the security manager
 
 - 
resolveAndBindpublic static Configuration resolveAndBind(ModuleFinder before, List<Configuration> parents, ModuleFinder after, Collection<String> roots) Resolves a collection of root modules, with service binding, to create configuration.This method works exactly as specified by resolveexcept that the graph of resolved modules is augmented with modules induced by the service-use dependence relation.More specifically, the root modules are resolved as if by calling resolve. The resolved modules, and all modules in the parent configurations, withservice dependencesare then examined. All modules found by the given module finders thatprovidean implementation of one or more of the service types are added to the module graph and then resolved as if by calling theresolvemethod. Adding modules to the module graph may introduce new service-use dependences and so the process works iteratively until no more modules are added.As service binding involves resolution then it may fail with FindExceptionorResolutionExceptionfor exactly the same reasons specified inresolve.- Parameters:
- before- The before module finder to find modules
- parents- The list parent configurations in search order
- after- The after module finder to locate modules when not located by the- beforemodule finder or in parent configurations
- roots- The possibly-empty collection of module names of the modules to resolve
- Returns:
- The configuration that is the result of resolving, with service binding, the given root modules
- Throws:
- FindException- If resolution fails for any of the observability-related reasons specified by the static- resolvemethod
- ResolutionException- If resolution fails any of the consistency checks specified by the static- resolvemethod
- IllegalArgumentException- If the list of parents is empty, or the list has two or more parents with modules for different target operating systems, architectures, or versions
- SecurityException- If locating a module is denied by the security manager
 
 - 
emptypublic static Configuration empty() Returns the empty configuration. There are no modules in the empty configuration. It has no parents.- Returns:
- The empty configuration
 
 - 
parentspublic List<Configuration> parents() Returns an unmodifiable list of this configuration's parents, in search order. If this is the empty configuration then an empty list is returned.- Returns:
- A possibly-empty unmodifiable list of this parent configurations
 
 - 
modulespublic Set<ResolvedModule> modules() Returns an immutable set of the resolved modules in this configuration.- Returns:
- A possibly-empty unmodifiable set of the resolved modules in this configuration
 
 - 
findModulepublic Optional<ResolvedModule> findModule(String name) Finds a resolved module in this configuration, or if not in this configuration, the parent configurations. Finding a module in parent configurations is equivalent to invokingfindModuleon each parent, in search order, until the module is found or all parents have been searched. In a tree of configurations then this is equivalent to a depth-first search.- Parameters:
- name- The module name of the resolved module to find
- Returns:
- The resolved module with the given name or an empty Optionalif there isn't a module with this name in this configuration or any parent configurations
 
 
- 
 
-