Return to site
JPMS: 'transitive' dependency
AKA requires transitive—implied readability.
·
To specify a dependency on another module and to ensure that other modules reading your module also read that dependency—known as implied readability
=>Use requires transitive, as in:
Consider the following directive from the java.desktop module declaration:
In this case, any module that reads java.desktop also implicitly reads java.xml.
For example, if a method from the java.desktop module returns a type from the java.xml module, code in modules that read java.desktop becomes dependent on java.xml.
Without the requires transitive directive in java.desktop’s module declaration, such dependent modules will not compile unless they explicitly read java.xml.
Remember that dependencies are not transitive by default.
A transitive dependency is a transfer of dependencies to dependent modules.
One thing to keep in mind is that dependencies are only transferred to direct dependents.
Of course, you could always reuse transitive dependencies at the next level.
Transitive dependencies avoid having to repeat the dependency requirements.