关于dependencyManagement标签
今天说一说Maven的dependencyManagement标签,这个标签只负责维护版本号,父项目在这里添加了依赖后,子项目在写依赖时不需要手动指定版本号了,(注意:在dependencyManagement标签中加入的依赖后Maven不会立即导入此依赖,而是在子项目引用此依赖的时候Maven在会开始导入依赖) ,所以,在子项目引用此依赖时,只需要写artifactId和groupId,而version则由dependencyManagement帮助你管理。
下面是一个例子
...略过...
<dependencyManagement>
<dependencies>
<!--这个依赖的用处就是替你管理spring boot与其他各模块的版本号,帮你解决兼容性问题-->
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Cairo-SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--用途与上面依赖的相似-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
...略过...
以后在子项目中引用spring boot的相关模块时就可以写成这样
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
OK,就到这