The JPMS requires instruction can have two qualifiers static and transitive. For a module foo:
requires static bar;, makes resolution of thebarmodule optional at runtime,requires transitive bar;, allows each module that readsfooto also readbar. According to thejava.lang.moduleJavadoc this also means thatbarmust be present at both compiletime and runtime.
There is however a third option allowed:
module foo {
requires static transitive bar;
}
What is this combination supposed to do?
According to the Javadoc:
requiresdirectives that have thestaticmodifier express an optional dependence at run time. If a module declares that itrequires static Mthen resolution does not search the observable modules for M to satisfy the dependency. However, if M is recursively enumerated at step 1 then all modules that are enumerated andrequires static Mwill read M.
where "step 1" describes the computation of the closure of the set of root modules by the X requires transitive Y relation.
If I interpret this correctly, if a requires directive is both static and transitive, the foo module is not optional, since "step 1" requires its presence.
We often end up with such directives, when using the bnd-maven-plugin, which maps the OSGi resolution:=optional directive to static and the uses:=... directive to transitive.