Maven---学习心得---maven的Dependency Mechanism(依赖关系机制)
生活随笔
收集整理的這篇文章主要介紹了
Maven---学习心得---maven的Dependency Mechanism(依赖关系机制)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.概述:
dependency management是maven所擅長的東西之一,是maven的特色功能。
參考資料:1)maven官網(wǎng)documentation
2)
2.maven的依賴機制
1)maven中的依賴是可傳遞的(transitive denpendencies)
-
-
-
- pom.xml可以繼承parent pom.xml
- 可以自動繼承該項目所依賴的三方工程(dependencies)依賴的其他工程
- 由于maven管理的項目,其依賴是可傳遞的,所以就容易出現(xiàn)一個問題,那就是依賴有可能形成一個循環(huán)(cycle)
-
-
2)dependency scope依賴范圍是可控的
There are 6 scopes available:
-
-
- compile(默認)
This is the default scope, used if none is specified【指定】. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated【傳播】 to dependent projects. - provided
This is much like?compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope?provided?because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive. - runtime
This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath. - test
This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive. - system
This scope is similar to?provided?except that you have to provide the JAR which contains it explicitly【顯式地】. The artifact is always available and is not looked up in a repository. - import(only available in Maven 2.0.9 or later)
This scope is only supported on a dependency of type?pom?in the?<dependencyManagement>?section. It indicates the dependency to be replaced with the effective list of dependencies in the specified【指定的】 POM's?<dependencyManagement>?section. Since they are replaced, dependencies with a scope of?import?do not actually participate in limiting the transitivity of a dependency.
- compile(默認)
-
-
2)怎么通過maven的pom.xml給自己的project添加external dependencies
?
轉載于:https://www.cnblogs.com/lxrm/p/6192665.html
總結
以上是生活随笔為你收集整理的Maven---学习心得---maven的Dependency Mechanism(依赖关系机制)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 朴素Paxos(Basic Paxos)
- 下一篇: 痞子衡嵌入式:第一本Git命令教程(4)