Howdy, You are on the right track and Guillame and I had a lot of discussions about this. IMO, best would be to wait for him (is on PTO I think) and have a chat face to face?
Thanks T On Mon, Aug 5, 2024 at 2:07 PM Martin Desruisseaux < martin.desruisse...@geomatys.com> wrote: > Maven 4 has two very similar public interfaces for dependencies: > > * Dependency > * DependencyCoordinate > > They both have groupId, artifactId, classifier, version, extension, type > and scope. Differences that I observed are: > > * Spelling: `Dependency.isOptional()` versus > `DependencyCoordinate.getOptional()`. > * Return type of the `getVersion()` method: `Version` versus > `VersionConstraint`. > * Methods present only in `DependencyCoordinate`: > o getExclusions() > * Methods present only in `Dependency`: > o getBaseVersion() > o isSnapshot() > o toCoordinate() > > The Javadoc does not explain those differences, neither why they exist. > I suspect that `DependencyCoordinate` is the dependency has declared in > the POM, while `Dependency` is the dependency effectively used after > resolution. For example, with the range of versions > (`VersionConstraint`) resolved to a single version (`Version`). Is that > right? If so, would it make sense to add a `getPath()` method in > `Dependency` since it has been resolved? I think it would make the API > easier to understand compared to the current approach of using > `Map<Dependency, Path>` returned by `DependencyResolverResult`. > > The reason why I ask is because there is path-derived information that > need to be associated to a dependency, in particular `ModuleDescriptor`. > With the current design, those information are provided by > `DependencyResolverResult`. It would be more natural to have them in > `Dependency`. I.e., instead of: > > * DependencyResolverResult > o Map<Dependency, Path> getDependencies() > o Optional<ModuleDescriptor> getModuleModuleDescriptor(Path) > o Optional<String> getModuleName(Path) > > We could have: > > * DependencyResolverResult > o Set<Dependency> getDependencies() > * Dependency > o Path getPath() > o Optional<ModuleDescriptor> getModuleModuleDescriptor() > o Optional<String> Dependency.getModuleName() > > The choice would determine the form of pull request #1625, which is > needed for the new compiler plugin and will also be needed by at least > javadoc, surefire and exec plugins. > > As a side note, do we really need those interfaces to be independent? > Couldn't we define Dependency as a subtype of DependencyCoordinate > together with Artifact as a subtype of ArtifactCoordinate? It would > remove the need for `toCoordinate()` methods and reduce a little bit the > amount of wrappings between different kinds of objects in Maven core, > which cost me hours of debugging (pull request #1621 is small, but was > hard to find). > > Martin > >