maven坐标Dependencies和Exclusions详解
来源:互联网 发布:java 连接池实现原理 编辑:程序博客网 时间:2024/06/07 09:05
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
- maven坐标Dependencies和Exclusions详解
- maven坐标Dependencies和Exclusions详解
- maven可选依赖(Optional Dependencies)和依赖排除(Dependency Exclusions)
- maven可选依赖(Optional Dependencies)和依赖排除(Dependency Exclusions)
- Maven开发笔记(二)—— Maven中的可选依赖(Optional Dependencies)和依赖排除(Dependency Exclusions)
- maven坐标和依赖详解
- Maven学习笔记九:Maven坐标和依赖(坐标详解)
- Maven-DependencyManagement和Dependencies
- maven中DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- Maven中的DependencyManagement和Dependencies
- maven坐标详解
- 数据库学习-事务
- Spring Boot MyBatis升级篇-注解-动态SQL(if test)-方案二:@Provider
- View的measure过程
- Lua在Windows下的配置、安装、运行
- #####好######Python标准库系列之Redis模块
- maven坐标Dependencies和Exclusions详解
- Spring aop编程ProxyFactory切入点运行原理。
- MongoDB SpringMVC整合mongodb 3.0驱动的异常解决
- XMind 中文版下载中心 绿色便携本
- JDBC处理SQL NULL值
- 利用String类或StringBuffer类的方法,对输入的Email地址进行有效性验证。提示: 1)Email地址中应包含“@”和“.”符号; 2)“@”符号应该在“.”符号之前; 3
- JSON put ,accumulate,element 区别
- struts2 验证框架
- 数据结构--完全二叉树的判断