Are modifiers `static` and `transitive` incompatible?

Piotr P. Karwasz piotr.karwasz at gmail.com
Wed Feb 7 19:22:27 UTC 2024


Hi Alex,

On Wed, 7 Feb 2024 at 18:42, Alex Buckley <alex.buckley at oracle.com> wrote:
>
> 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_).

By "minimal compile time resolution" I mean the one described at the
end of `java.lang.module`'s Javadoc[1]:

> Resolution may be partial at compile-time in that the complete transitive closure may not be required to compile a set of modules. Minimally, the readability graph that is constructed and validated at compile-time includes the modules being compiled, their direct dependencies, and all implicitly declared dependencies (requires transitive).

According to this description, if `log4j-core` had a `requires static
transitive foo` directive it is not enough add `foo` as Maven
dependency of `log4j-core` with `<optional>true</optional>`, because
Maven does not resolve optional dependencies of direct dependencies.
Putting `foo` in the Maven `provided` scope does not work either.

This is my main problem with any `requires static transitive bar;`
directive in a module descriptor `foo` that has an optional Maven
dependency on `bar`: it forces users of  `foo` to manually add `bar`
as Maven dependency in their project (it can be `provided` so it does
not propagate). Remark that this concerns only direct users of `foo`.
Indirect users do not need to add `bar` to their dependencies.

Piotr

[1] https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/module/package-summary.html


More information about the jigsaw-dev mailing list