Are JPMS modifiers `static` and `transitive` incompatible?

41 views Asked by At

The JPMS requires instruction can have two qualifiers static and transitive. For a module foo:

  • requires static bar;, makes resolution of the bar module optional at runtime,
  • requires transitive bar;, allows each module that reads foo to also read bar. According to the java.lang.module Javadoc this also means that bar 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 the static modifier express an optional dependence at run time. If a module declares that it requires 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 and requires 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.

0

There are 0 answers