The more I spend time with JPMS and maven, the more I wonder if we need to
have some kind of additional metadata for our dependency declarations.

Up until Java 8, dependencies were pretty straightforward: They go on the
classpath depending on their scope. Some are only on the compile classpath,
some on the test classpath, some on the runtime classpath.

In the Java 9+ world, things get trickier.

- If a project builds a regular jar (no module descriptor or only an entry
in the Manifest), then the world still works as above.
- If a project builds a JPMS module (has a module descriptor)...
  - A dependency that has a module descriptor (module-info) normally goes
on the module path
  - A dependency that does not have a module descriptor may go onto the
module path (where it lives as an automatic module) *OR* could go on the
class path where it would be part of the unnamed module. The latter may be
necessary for dependencies that have overlapping packages.

So for any dependency, there is a default (classpath for a regular project,
module path for a project with a module descriptor) but there are
situations where that default may need to be overridden. And, what is
worse, there may be situations where overriding depends on whether it is
used for compilation or testing.

There is currently no way to communicate to maven as a user whether a given
dependency should be on the module path or the class path short of adding a
config option to a plugin that controls this. We have this scenario in
multiple places where dependency specific configuration is added to a
plugin because there is no better place.

I wonder if there is an opportunity when overhauling the POM right now, to
add a "properties bag" to each dependency. Basically

<dependency>
  <groupId>...
  <artifactId>...
  <version>...
  <type>...
  <scope>...
  <optional>...




*  <properties>    <some-key>some-value</some-key>
<some-other-key>some-value</some-other-key>  </properties>*</dependency>

which would allow general metadata association to the dependencies.

In that scenario, I could see using e.g.

<properties>
  <module-path>true</module-path>
</properties>

or

<properties>
  <module-path>compile</module-path>
</properties>

to hint the various plugins whether a given dependency should be treated as
a module path or a classpath element.

-h

Reply via email to