Are modifiers `static` and `transitive` incompatible?
Alex Buckley
alex.buckley at oracle.com
Wed Feb 7 16:08:58 UTC 2024
On 2/7/2024 6:14 AM, Piotr P. Karwasz wrote:
> If a user declares `log4j-core` as compile dependency and adds
> `requires org.apache.logging.log4j.core` to their module descriptor,
> the `requires static transitive` directives will cause compilation
> errors, since the minimal compilation time resolution requires all
> transitive dependencies of direct dependencies. That is why we
> manually remove the `transitive` keyword from those dependencies.
By "minimal compile time resolution", are you referring to something
that Maven does? If so, and you're reasoning about how `requires static
transitive` would be interpreted, then be aware that the term
"transitive" means different things in the Maven world and the Java
module world. Ultimately it's about indirect dependencies in both
worlds, but in Maven a "transitive dependency" is one level further
_down_ from the depending artifact, while in Java modules, saying
`requires transitive` makes the requiring module itself an indirect
dependency (of a module one level further _up_).
> Would it be wiser not to export packages that depend on optional
> dependencies?
Yes.
The right way to encode optional dependencies is in the programming
model: by programming to an interface for which ServiceLoader finds
implementations; if there are zero implementations, then the program
will find this out and can deal with it.
Alex
More information about the jigsaw-dev
mailing list