Maven dependency, maven
Optional dependencies:
1. Which version is called? The shortest dependency Length
For example, if A-> B-> C-> D 2.0, A-> E-> D 1.0, call D 1.0.
To avoid this situation, you can directly define A-> D 2.0, that is, the dependency explicitly defined by yourself is always called first, regardless of the version level.
2. if the version is not declared? The latest version is used by default.
3. exclude A dependency, such as A-> B-> C. A can explicitly exclude the dependency on C.
<dependency> <groupId>group-a</groupId> <artifactId>artifact-a</artifactId> <version>1.0</version> <exclusions> <exclusion> <groupId>group-c</groupId> <artifactId>excluded-artifact</artifactId> </exclusion> </exclusions> </dependency>
4. Optional dependencies, such as B-> C, but are declared as optional. C is no longer dependent on A-> B, which is equivalent to being excluded by default.
Of course, you can also explicitly add dependencies on C. The two are irrelevant.
5. scope:
- Compile(Default, saving)
- Provided, Which will be provided by JDK or WebServer, such as Servlet API, required during compilation,Not passed
- Runtime, Used for running, not required during compilation,Not passed
- Test, Used for testing,Not passed
- System, Indicates that this is provided explicitly, and you do not need to find it in the code base. This is required during compilation,Not passed
- ImportUsed only<DependencyManagement>And does not affect the transfer.
<Dependencies> <dependency> <groupId> sun. jdk </groupId> <artifactId> tools </artifactId> <version> 1.5.0 </version> <scope> system </scope> <systemPath >$ {java. home }/.. /lib/tools. jar </systemPath> Self-specified </dependency> </dependencies>