`requires static` versus service binding
Remi Forax
forax at univ-mlv.fr
Wed Jan 8 18:35:04 UTC 2025
Hello,
It depends how the service is resolved, i.e. if there is a fallback strategy or not.
The mechanism of "require static" is not restricted to work only with services.
It's a mechanism to express the fact that you can have a runtime dependency which is present or not.
A module that required a static module should have a code that deal with the fact that the dependency may not be present at runtime.
By example, jackson has a mechanism of runtime extensions, so it works with different versions of the jdk using the same code, because the code of jackson can check at runtime if an extension is present or not.
regards,
Rémi
> From: "David Lloyd" <david.lloyd at redhat.com>
> To: "jigsaw-dev" <jigsaw-dev at openjdk.java.net>
> Sent: Wednesday, January 8, 2025 6:57:08 PM
> Subject: `requires static` versus service binding
> It is not uncommon for a library to contain a provider for a service where the
> service resides in an optional dependency. It is also sometimes desirable to
> use a service from an optional dependency.
> In JPMS, we can use `requires static` to indicate that the library will function
> without the dependency being present. We can declare that we use or provide a
> service from the optional dependency. Compilation will complete successfully in
> this case, because the descriptor is valid.
> However, at run time, the module will fail to resolve if any provider or uses
> comes from a module that is not present when the layer is resolved. This is not
> desired behavior, because the user has already opted in to and indicated that
> the dependency in question is optional, and should not cause a run time problem
> if not present.
> The current behavior is inconsistent between compile and run time, and should be
> revisited.
> --
> - DML • he/him
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jigsaw-dev/attachments/20250108/00899218/attachment-0001.htm>
More information about the jigsaw-dev
mailing list