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

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

 

posted on 2016-12-17 17:06  LXRM-JavaWeb、ML  阅读(424)  评论(0编辑  收藏  举报

导航