1、概念介绍 
Dependencies:是可选依赖(Optional Dependencies) 
Exclusions:是依赖排除(Dependency Exclusions) 
2、Dependencies 
(1)当一个项目A依赖另一个项目B时,项目A可能很少一部分功能用到了项目B,此时就可以在A中配置对B的可选依赖。举例来说,一个类似hibernate的项目,它支持对mysql、oracle等各种数据库的支持,但是在引用这个项目时,我们可能只用到其对mysql的支持,此时就可以在这个项目中配置可选依赖。 
(2)配置可选依赖的原因: 
1)节约磁盘、内存等空间; 
2)避免license许可问题; 
3)避免类路径问题,等等。 
(3)示例:

<project>
...
<dependencies>
<!-- declare the dependency to be set as optional -->
<dependency>
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
<version>1.0</version>
<scope>compile</scope>
<optional>true</optional> <!-- value will be true or false only -->
</dependency>
</dependencies>
</project>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

  假设以上配置是项目A的配置,即:Project-A –> Project-B。在编译项目A时,是可以正常通过的。如果有一个新的项目X依赖A,即:Project-X -> Project-A。此时项目X就不会依赖项目B了。如果项目X用到了涉及项目B的功能,那么就需要在pom.xml中重新配置对项目B的依赖。假设A->B, B->x(可选), B->y(可选)。这里由于x,y是可选依赖,依赖不会传递,x,y将不会对a有任何影响

3、Exclusions 
(1)当一个项目A依赖项目B,而项目B同时依赖项目C,如果项目A中因为各种原因不想引用项目C,在配置项目B的依赖时,可以排除对C的依赖。 
(2)示例(假设配置的是A的pom.xml,依赖关系为:A –> B; B –> C):

<project>
...
<dependencies>
<dependency>
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectC</groupId>
<artifactId>Project-C</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

4、maven的依赖调解有两大原则:路径最近者优先;第一声明者优先。 
5、maven的归类依赖

<properties>
<springframework.version>2.5.6<springframework.version>
</properties>
  • 1
  • 2
  • 3

定义此属性值后,maven会将pom中的所有的${springframework.version}替换成实际值2.5.6

转自:http://blog.csdn.net/eff666/article/details/51991465

maven坐标Dependencies和Exclusions详解的更多相关文章

  1. 史上最全的maven pom.xml文件教程详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  2. 【转】maven核心,pom.xml详解

    感谢如下博主: http://www.cnblogs.com/qq78292959/p/3711501.html maven核心,pom.xml详解 什么是pom?    pom作为项目对象模型.通过 ...

  3. 史上最全的maven的pom.xml文件详解(转载)

    此文出处:史上最全的maven的pom.xml文件详解——阿豪聊干货 <project xmlns="http://maven.apache.org/POM/4.0.0" x ...

  4. [转]Maven的pom.xml文件详解

    Maven的pom.xml文件详解------Build Settings 2013年10月30日 13:04:01 阅读数:44678 根据POM 4.0.0 XSD,build元素概念性的划分为两 ...

  5. Maven依赖中的scope详解,在eclipse里面用maven install可以编程成功,到服务器上用命令执行报VM crash错误

    Maven依赖中的scope详解 项目中用了<scope>test</scope>在eclipse里面用maven install可以编译成功,到服务器上用命令执行报VM cr ...

  6. Maven全局配置文件settings.xml详解(转)

    Maven全局配置文件settings.xml详解   目录 一.概要 1.settings.xml的作用2.settings.xml文件位置3.配置的优先级 二.settings.xml元素详解 1 ...

  7. 史上最全的maven的pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  8. maven的pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  9. Maven的pom.xml文件详解【转载】

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

随机推荐

  1. hexdump命令

    hexdump hexdump用于以16进制.10进制.8进制.ascii码形式打印文件内容,也可以是标准输入的内容. 用法 hexdump [选项] 文件 ... 选项 选项 参数 说明 -b   ...

  2. Selenium 对元素的判断(expected_conditions)(转载)

    我们在用webdriver去操作元素时,先要判断这个元素是否存在,存在才去操作,否则就会报错. selenium的expected_conditions模块提供了一些判断方法 场景 Expected ...

  3. XSS中的同源和跨域的问题

    学习自https://www.cnblogs.com/-qing-/p/10966047.html 也谈谈同源策略和跨域问题 1 同源策略 所谓同源策略,指的是浏览器对不同源的脚本或者文本的访问方式进 ...

  4. RedisTemplate中zset类型的使用

    简述 上一文中简述了使用StringRedisTemplate操作redis中的set类型,今天来记录一下操作zset类型的主要方法 代码 @RunWith(SpringRunner.class) @ ...

  5. java 手机号/身份证(*)加密隐藏中间某几位几位

    //手机号 保留前3 后4 String phone = "18771632488"; System.out.println(phone.replaceAll("(\\d ...

  6. 二、Smarty中的三种主要变量

    1.从PHP中分配的变量 $smarty -> assign(); 从PHP分配给模板使用的变量:动态变量 2.从配置文件中读取的变量 $smarty配置文件中的内容不是PHP读取,而是就在sm ...

  7. 类组件(Class component)和函数式组件(Functional component)之间有何不同

    类组件不仅允许你使用更多额外的功能,如组件自身的状态和生命周期钩子,也能使组件直接访问 store 并维持状态当组件仅是接收 props,并将组件自身渲染到页面时,该组件就是一个 ‘无状态组件(sta ...

  8. 通过daemon.json配置docker 2375 API端口,配置私有http仓库

    编辑daemon.json vi /etc/docker/daemon.json 配置如下内容即可 { "hosts":[ "tcp://0.0.0.0:2375&quo ...

  9. Oracle Rac 测试

      #还是使用之前的脚步来进行测试 #Author : Kconnie Pong Oracle@PONGDB:~> more load_balance.sh #!/bin/bash ..} do ...

  10. oracle delete 数据恢复

    /*1.FLASHBACK QUERY*/ --闪回到15分钟前 select *  from orders  as of timestamp (systimestamp - interval ''1 ...