持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第5天,点击查看活动详情
前言
其实最怕的就是在配置项目的时候遇上版本依赖问题
因为这个很烦尤其是对于初学者 单体项目还好因为这个模块本身就是父级 版本控制起来比较简单
但是如果在多模块的基础上 就要去慎重考虑Pom.xml 中版本依赖的问题
这个也会被面试官当作考察点之一 下面就稍微整理一下微服务下怎么做到依赖版本控制
普通项目
自己练手的项目我们可能就不会过多的对 依赖进行版本控制 一般只要项目能运行起来就万事大吉啦
这个是自己一个练手项目里面的依赖配置 因为是单体项目只有一个模块所以就什么依赖都塞进去 运气好就不会出现版本冲突问题 哈哈哈 当然这是一个反面教材 但是一旦这个项目体积大起来 依赖多了起来就会总成苦哈哈的找依赖配置 项目在配置过程中就要去计划解决这一点
<!--效验依赖-->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!--redis 对应依赖-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<!--easypoi相关依赖,用于操作Excel文件-->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.0.0</version>
</dependency>
单模块其实没有什么特别讲述的意义 现在微服务满天飞的情况 我们着重是讲一下 微服务的版本控制
版本控制(微服务)
从Maven 3.5.0-beta-1版本开始,就可以使用${revision}
, ${sha1}
和 ${changelist}
作为占位符来替换pom文件了。
注意:低版本Idea下使用${revision}
定义Parent版本时会提示错误“Reports that usage of properties in modules parent definition is prohibited”,但并不影响使用,只是Idea不支持这种写法而已
如果不能使用就要去升级版本
首先是在父文件里面使用 properties
进行版本控制

使用的时候就是使用占位符的形式
有点像Myabtis XMl的思想
使用 modules
引入子模块
使用 parent
指向父模块
因为子模块指向了父模块 父模块引用了子模块 所以有一种继承关系 可以理解成 java中的继承 子模块就能直接使用父模块的依赖
子模块就不再使用版本号 直接使用父模块的版本号