zoukankan      html  css  js  c++  java
  • 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

    学习的过程中总会得到一些心得体会,认真地将它们记录下来并分享给每一个愿意花费时间去阅读它们的人,然后意外地收获某个读者的评论,从而激发出新的感想,是一件十分令人欢快的事。如果你也在研习这方面的知识,欢迎加入到我们的队伍中来,和我们一起进步吧(^_^)
  • 相关阅读:
    模块化项目
    mysql mybatis-generator plugin 有page实体类的分页
    mysql mybatis-generator plugin 分页
    eclipse中mybatis generator插件的安装与使用,实现自动生成代码
    linux下安装mysql5.7.17及简单配置
    mybatis-mysql操作存储过程
    解决JSP路径问题的方法(jsp文件开头path, basePath作用)
    windows下开启mysql远程访问
    Java中hashCode的作用
    垃圾收集器与内存分配策略 (深入理解JVM二)
  • 原文地址:https://www.cnblogs.com/lxrm/p/6192665.html
Copyright © 2011-2022 走看看