You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
org.apache.maven.api.Dependency extends org.apache.maven.api.Artifact. This violates the OO principal that inheritance represents an is-A relation. A dependency is not an artifact. Arguably it has an artifact. However, artifacts are nodes in the graph while dependencies are the arcs. These aren't the same thing and mixing them up is a common source of confusion.
This may be a semantic problem. When we talk about a project's dependencies, we usually talk about the actual artifacts, not the requirement. So difficulty is that the resolution of an artifact is, most of the time, nothing, unless the dependency constraint undergo conflict resolution or something like that.
Anyway, I tried to make it more clear in the API by talking about "dependency coordinates", i.e. the requirement or constraint (expressed by a <dependency> xml element usually), and the resolved Dependency, which is the actual artifact pointer, and the DownloadedDependency when the artifact has actually been downloaded.
I don't think it's only a documentation problem, though it is a documentation problem. Most docs, both Maven's own and third party's and most discussions, have been cavalier about the distinction between dependencies and artifacts. However after spending multiple years deep in the weeds of Maven dependency management, I am increasingly convinced that being very precise about this is absolutely critical to explaining and understanding how Maven works.
Currently package-info says this and it does describe the current class inheritance structure. However I don't think that inheritance hierarchy is correct, and it does lead to confusion.
* <p>{@link org.apache.maven.api.DependencyCoordinates} instances represent a dependency element in a POM.
* A {@code DependencyCoordinates} extends {@code ArtifactCoordinates} with additional information about how
* the artifact will be used: type, scope and obligation (whether the dependency is optional or mandatory).
* The version and the obligation may not be defined precisely.</p>
*
* <p>{@link org.apache.maven.api.Dependency} instances represent artifacts in the repository
* that are dependencies of the project.
* They are created when <dfn>resolving</dfn> a {@code DependencyCoordinates}.
* Resolving is the process that clarifies the obligation (optional or mandatory),
* selects a particular version, and downloads the artifact into the local repository.</p>
This is a classic example of is-a/has-a confusion in OO. It is true currently that {@link org.apache.maven.api.Dependency} instances represent artifacts in the repository. However, that shouldn't be the case. Instead something like "ResolvedDependency" should contain (not inherit from) an Artifact field.
Activity
jira-importer commentedon May 27, 2025
Guillaume Nodet commented
This may be a semantic problem. When we talk about a project's dependencies, we usually talk about the actual artifacts, not the requirement. So difficulty is that the resolution of an artifact is, most of the time, nothing, unless the dependency constraint undergo conflict resolution or something like that.
Anyway, I tried to make it more clear in the API by talking about "dependency coordinates", i.e. the requirement or constraint (expressed by a
<dependency>xml element usually), and the resolvedDependency, which is the actual artifact pointer, and theDownloadedDependencywhen the artifact has actually been downloaded.The javadoc may certainly be enhanced on classes and package (https://github.com/apache/maven/blob/0710deb4fd9b132183597dbaed9734eeff621fa1/api/maven-api-core/src/main/java/org/apache/maven/api/package-info.java).
jira-importer commentedon May 28, 2025
Elliotte Rusty Harold commented
I don't think it's only a documentation problem, though it is a documentation problem. Most docs, both Maven's own and third party's and most discussions, have been cavalier about the distinction between dependencies and artifacts. However after spending multiple years deep in the weeds of Maven dependency management, I am increasingly convinced that being very precise about this is absolutely critical to explaining and understanding how Maven works.
Currently package-info says this and it does describe the current class inheritance structure. However I don't think that inheritance hierarchy is correct, and it does lead to confusion.
This is a classic example of is-a/has-a confusion in OO. It is true currently that {
@linkorg.apache.maven.api.Dependency} instances represent artifacts in the repository. However, that shouldn't be the case. Instead something like "ResolvedDependency" should contain (not inherit from) an Artifact field.