Home  >  Article  >  Java  >  Detailed explanation of Maven dependency diagram examples

Detailed explanation of Maven dependency diagram examples

零下一度
零下一度Original
2017-06-26 14:31:031376browse

Transitive dependencies and dependency scope

Maven's dependencies are transitive, such as A->B, B->C, then A indirectly depends on C , this is the transitivity of dependency, where A is the first direct dependence on B, B is the second direct dependence on C, and C is the transitive dependency of A.

In normal development, if our project depends on spring-core, the dependency scope is compile, and spring-core depends on commons-logging, and the dependency scope is also compile, then our project will depend on commons-logging The scope of this transitive dependency is compile. The scope of the first direct dependency and the scope of the second direct dependency determine the scope of the transitive dependency. We use the following table to illustrate, in which the leftmost column is the first direct dependency, and the top column is the second direct dependency. Crossed in the middle are transitive dependency scopes.

##RuntimeTestTestTestProvidedProvidedProvidedProvided##RuntimeFor example: the first direct dependency scope is Test, and the second direct dependency scope is Compile, then the transitive dependency scope is Test. You can judge based on this table.

Compile

Test

Provided

Runtime

##Compile

Compile

Runtime

Runtime

Looking at the table carefully, we can find this pattern:

When the scope of the second direct dependency is compile, the scope of the transitive dependency is the same as the first The scope of direct dependencies is consistent;
  • When the scope of the second direct dependency is test, the dependency will not be passed;
  • When the scope of the second direct dependency is test, the dependency will not be passed; When the scope of the second direct dependency is provided, only the dependency of the first direct dependency is also provided, and the scope of the transitive dependency is also provided;
  • When the second direct dependency is When the scope of the dependency is runtime, the scope of the transitive dependency is the same as the scope of the first direct dependency, with the exception of compile. In this case, the scope of the transitive dependency is runtime.

The above is the detailed content of Detailed explanation of Maven dependency diagram examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:ArrayList collectionNext article:ArrayList collection