码迷,mamicode.com
首页 > 其他好文 > 详细

Maven--->学习心得--->maven的Dependency Mechanism(依赖关系机制)

时间:2016-12-17 20:12:00      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:provided   功能   lis   jdk   ipa   limit   run   man   通过   

1.概述:

  dependency management是maven所擅长的东西之一,是maven的特色功能。

  参考资料:1)maven官网documentation

        2)

2.maven的依赖机制

  1)maven中的依赖是可传递的(transitive denpendencies)

        • pom.xml可以继承parent pom.xml
        • 可以自动继承该项目所依赖的三方工程(dependencies)依赖的其他工程
        • 由于maven管理的项目,其依赖是可传递的,所以就容易出现一个问题,那就是依赖有可能形成一个循环(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.

  2)怎么通过maven的pom.xml给自己的project添加external dependencies

 

Maven--->学习心得--->maven的Dependency Mechanism(依赖关系机制)

标签:provided   功能   lis   jdk   ipa   limit   run   man   通过   

原文地址:http://www.cnblogs.com/lxrm/p/6192665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!