Return to site

JPMS: 'requires' directive

· java

A requires module directive specifies that this module depends on another module—this relationship is called a module dependency.
Each module must explicitly state its dependencies.

When module com.mycompany.myotherpackage requires module com.mycompany.mypackage,
module com.mycompany.myotherpackage is said to read module com.mycompany.mypackage
and module com.mycompany.mypackage is read by module com.mycompany.myotherpackage.

To specify a dependency on another module, use requires, as in:

giving a module-info like this:

Now, the com.mycompany.myotherpackage module is able to access everything
that the com.mycompany.mypackage module has made available to foreign modules.
Control is left up to the com.mycompany.mypackage module to decide what can be accessed.
By default nothing's accessible.
The dependent module, in this case com.mycompany.myotherpackage,
gets all of the packages exposed by the exporting module.