maven版本冲突解决

maven版本冲突解决

maven两大功能:依赖管理和一键构建

依赖管理:分为直接依赖和间接依赖

直接依赖:在pom文件中直接导入的jar包坐标,直接依赖于次jar包
间接依赖:A依赖于B,B依赖于C,那么A间接依赖于C
解决jar包冲突的三个原则:

  1. 第一声明优先原则,pom坐标在最上面的优先
  2. 路径近者优先原则,如果A直接依赖于B1,间接依赖于B2,那么B1优先
  3. jar包排除,在 dependency 标签中使用 exclusion 标签进行排除
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-dependencies</artifactId>
			<version>${spring-boot.version}</version>
			<exclusions>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring-beans</artifactId>
				</exclusion>
			</exclusions>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

版本锁定

  1. 使用 properties 标签进行版本的声明,properties 标签中是键值对的形式,以下声明了一个jar的版本号
<properties>
	<spring-boot.version>2.1.5.RELEASE</spring-boot.version>
</properties>
  1. 使用 dependencyManagement 标签,内嵌 dependencies 标签,以下使用上面的版本号进行锁定
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-dependencies</artifactId>
			<version>${spring-boot.version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>
  1. **说明:**锁定版本号不代表已经引入了此jar包,需要单独声明
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值