Depending in the Java Module System

Overview

In the Java Module System, the concept of "depending" is crucial for understanding how modules interact with each other. A module that depends on another module is referred to as the "depending" module. This relationship is established through the requires directive, which specifies the modules that a given module depends on.

Unnamed Module

One important aspect of depending is that it is not possible to depend on the unnamed module. The unnamed module, by definition, has no name, and therefore, no module can reference it in a requires directive. This restriction is in place to ensure that the module system maintains a reliable configuration. Since the unnamed module cannot be depended upon by other modules, it remains isolated from the modular system.

Automatic Modules

Automatic modules serve a specific purpose in the module system. They allow explicit modules to depend on plain JAR files, facilitating the transition to a fully modularized system without waiting for all dependencies to be modularized. However, this approach comes with a caveat: if the JAR's manifest does not include the Automatic-Module-Name entry, the dependency becomes fragile. This fragility arises because the module name is derived from the JAR file name, which can lead to inconsistencies and conflicts.

Breaking Dependency Cycles

In some cases, dependency cycles can occur, where two or more modules depend on each other, creating a circular dependency. To address this issue, the concept of "depending" is used to identify the module that originally depends on another module, referred to as the "depended" module. To break the cycle, a service is introduced in the "depending" module, and the dependency is inverted. This inversion allows the "depended" module to depend on the service provided by the "depending" module, effectively breaking the cycle.

Accessing Exposed Types

The depending module often needs to access the types of another module, known as the exposing module. This is necessary when the exposing module uses certain types in its public API. The depending module must have access to these types to function correctly, which is facilitated by the module system's ability to manage dependencies and access control.