1, coordinates-find the important basis of project dependence
<groupId>cmbc.com.cn</groupId> <artifactid>myapp</artifactid><version>1.0- Snapshot</version><packaging>war</packaging>
Description: A, groupId, Artifactid, version must be configured, packaging is optional, not configured defaults to jar
b, the project component name corresponds to the coordinates, usually artifactid-version.packaging, the above coordinate corresponding component name is called
Myapp-1.0-snapshot
2. Dependent configuration
<project> <dependencies> can contain multiple <dependency> <dependency> <groupid >...</groupId> <artifactId>...</artifactId> <version>...</version> <type>...</type> coordinate type, corresponding to the packaging <scope>...</scope> dependency range defined by the project coordinates <optional>...</optional> tag dependencies are optional <exclusions> exclude transitive dependencies ... </exclusions> </dependency> </dependencies></project>
3. Dependency details
A, the type of dependency range
b, the role of the scope of dependence
MAVEN compiles, tests, runs Classpath, and relies on a range of dependencies to control the relationship between dependencies and three kinds of classpath.
A, project a relies on b,b dependent on C, then C is a transitive dependency. MAVEN introduces the necessary indirect dependencies into the project in the form of transitive dependencies.
B. Determination of transitive dependency range
Project a relies on b,b for C, then B is the first direct dependence of a, C is the second direct dependence of B, and C is the transitive dependency of a. The scope of the first and second direct dependencies determines the scope of the transitive dependency, as shown below, with the first direct dependency on the left, which is the second direct dependency range, and the transitive dependency range in the middle:
When multiple direct dependencies on a project depend on the same other dependency in their own dependency path, which path should be introduced?
Rule: Different path length, shortest path priority; Same path length, first declaration preferred
Suppose a relies on b,b dependent on C (optional), D (optional) (Pom.xml files in Project B are dependent on C and D, <dependency> are added <optional>true</optional> in the declaration). Optional dependencies are not transitive, so C or D dependencies cannot be introduced in a project, and if you need to use C or D you need to rely directly on C or D in a project
Transitive dependencies implicitly introduce many dependencies, greatly simplifying the management of project dependencies. However, you need to use <exclusions> exclude dependencies in the following situations:
A, a dependent b,b dependent C,c (snapshot version) instability may affect project a. You need to exclude C at this point and introduce a stable version of C.
b, may be due to copyright reasons, C (stable version) is not in the central warehouse, and the D project is an alternative to the implementation. You need to exclude C at this point and introduce D