4. Multi-module Projects

1. 理解项目继承关系

1.1 只有一个纯粹的继承项目

  1. 层次结构如下:
    image.png
  2. 父pom(不感知下一级):


    image.png
  3. 子pom


    image.png
  4. 执行mvn clean package
    在父层面执行,子不会被执行
    在子pom执行,则会看到继承来的效果
  5. 如果parent的pom不是子的上一层目录


    image.png

2. 理解项目aggregation关系

最大的特定是如果在聚集工程的pom上执行某个动作,则它包含的所有module都会执行这个动作(比如aggregate modules and build them together)。

  1. 层次结构
    image.png
  2. 父pom
    image.png
  3. 子pom(不感知父pom的存在)
    image.png
  1. 执行mvn clean package
    在aggregate pom执行命令时,子pom也会依次自动执行,虽然子不感知aggregate pom的存在


    image.png
  2. 如果包含的模块是兄弟文件夹怎么办(默认是下一级文件夹)
    image.png

3. aggregation+继承关系

  1. 父pom
    image.png
  2. 子pom
    image.png
  3. 执行mvn clean package

4. multi-module 依赖管理

关键是dependencyManagement的用处,为何有时不直接在father pom中使用dependency

4.1 父pom
image.png

4.2 子pom
image.png

4.3 执行mvn clean test

忽略

4.4 执行mvn dependency:tree

可以看到依赖关系

5. multi-module 插件管理

比如我们想让某些子工程在打包的时候把一些资源打进去,而另外一些子工程不需要,则此时可以在父pom中统一定义,然后子pom有选择的使用这些插件

default lifecycle有个generate-resources phase(主要用来为需要打包进最终制品的资源提供产生方式)

5.1 父pom
image.png

5.2 需要的子pom

image.png

5.3 执行mvn clean test

执行完毕后看到下面文件被copy到class文件夹下
image.png

5. 选择性的构建modules

5.1 层次结构
image.png

5.2
image.png

5.3 两个子pom
image.png

image.png

5.4 运行命令
image.png
image.png

你可能感兴趣的:(4. Multi-module Projects)