The JPMS requires
instruction can have two qualifiers static
and transitive
. For a module foo
:
requires static bar;
, makes resolution of thebar
module optional at runtime,requires transitive bar;
, allows each module that readsfoo
to also readbar
. According to thejava.lang.module
Javadoc this also means thatbar
must 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:
requires
directives that have thestatic
modifier express an optional dependence at run time. If a module declares that itrequires static M
then 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 M
will 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
.