Spring Cloud微服务实战 打造企业级优惠券系统 2-3 Maven多模块项目

0    课程地址

https://coding.imooc.com/lesson/380.html#mid=28219

1    重要内容
1.1  depencyMangeMent和dependency的区别

dependencies即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)

dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且versionscope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。

一般我们都使用dependencyManagement

1.2  相关特性

a  父模块pom文件的配置(packaging必须为pom):

<groupId> com.imooc.coupon</groupId>
<artifactId> imooc-coupon</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>

b  聚合子模块:使用modules标签

<modules>
<module>coupon-common</module>
<module>coupon-template</module>
<module>coupon-settlement</module>
<module>coupon-distribution</module>
</modules>

c  父模块统一管理依赖包 使用dependencyManagement标签

<!--标识Springcloud 的版本-->
<
dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

d  子模块需要在pom中声明父模块:使用parent标签

<parent>
<artifactId>imooc-coupon</artifactId>
<groupId>com.imooc.coupon</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
2    其他内容
2.1  为什么使用多模块项目

a  解决编译时间长的问题。

b  继承重用。

原文地址:https://www.cnblogs.com/1446358788-qq/p/14232948.html