blob: 0a3081030cfa01c664868e4df2d93596e4b3dd6c [file] [log] [blame]
-----
Comparison: Dependency vs Artifact vs MavenProject
-----
Robert Scholte
-----
2015-12-28
-----
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
~~ NOTE: For help with the syntax of this file, see:
~~ http://maven.apache.org/doxia/references/apt-format.html
Comparison: Dependency vs Artifact vs MavenProject
Here's a small matrix which should help you choosing the right instance.
In general:
* an Artifact holds a file mapped on a certain coordinate (GAV + classifier + extension),
* a {{{/ref/current/maven-model/maven.html#class_dependency}Dependency}} contains an artifact and has transitive information,
* a MavenProject holds a pom-file, an optional main file derived from the packaging, and can have attached files (= with classifier and extension), all using the same GAV.
[]
*--------------------+-------------+----------------+---------------+
|| || Dependency || Artifact || MavenProject ||
*--------------------+-------------+----------------+---------------+
| Has dependencies | yes | no | yes |
*--------------------+-------------+----------------+---------------+
| filetype reference | {{{/ref/current/maven-core/artifact-handlers.html}type}} | file extension | packaging |
*--------------------+-------------+----------------+---------------+
| version ranges | yes | no | no |
*--------------------+-------------+----------------+---------------+
| scope | yes | no | no |
*--------------------+-------------+----------------+---------------+
| attached artifacts | no | no | yes |
*--------------------+-------------+----------------+---------------+
This implies the following:
* From dependency to artifact is possible, since you can map a type to an extension (see {{{/ref/current/maven-core/artifact-handlers.html}default dependency types}}).
However, it is not possible to go from artifact back to dependency, there are several types which have jar as file extension for example.
* There's no such thing as transitive artifacts. Filtering during resolution is based on DependencyFilters,
ArtifactFilters can only be applied afterwards, hence are less powerful.
[]
Notice that for historical reasons, Maven internal {{{/ref/current/maven-artifact/apidocs/org/apache/maven/artifact/Artifact.html}Artifact API}}
mixes dependency and artifact concepts.