1.POM 的父子关系:
2.三个工程之间的调用关系:
3.打包顺:sub1-Proj→sub2-Proj→war-Proj
在parent工程中追加:
<modules>
<module>../sub1-Proj</module>
<module>../sub2-Proj</module>
<module>../war-Proj</module>
</modules>
直接在parent工程上执行install 或者package命令,就会依次编译。
4.聚合模块(父工程)作用1:
父工程是一个pom工程,通常只是用来帮助其子模块构建的工具,本身并没有实质的内容。所有的子模块都继承于父模块,父模块用来做整个项目的版本控制,也就是项目中所有要使用到的jar包的版本都集中由父工程管理。子项目中的pom.xml只放自己个性的东西。在编译和打包等 其他阶段,都可以统一在父项目中来进行,maven会自动操作其中的子项目,提高了效率。
5.父工程pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 親POM -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath />
</parent>
<!-- プロジェクト名称・概要 -->
<name>Super POM</name>
<description>Super POMです。</description>
<!-- Super POM -->
<groupId>xx.xx.xx</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputDirectory>target/classes</project.build.outputDirectory>
<maven.test.skip>true</maven.test.skip>
</properties>
<!-- BUILDプロセスの記述 -->
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<!-- pluginManagementの定義 -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- springboot dev用(hot-load) -->
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>../sub1-Proj</module>
<module>../sub2-Proj</module>
<module>../war-Proj</module>
</modules>
</project>
5.子工程[sub1-Proj]pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xx.xx.xx</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>sub1-Proj</artifactId>
<name>sub1-Proj</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
6.子工程[sub2-Proj]pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xx.xx.xx</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>sub2-Proj</artifactId>
<name>sub2-Proj</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>xx.xx.xx</groupId>
<artifactId>sub1-Proj</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
7.子工程[war-Proj]pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xx.xx.xx</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>war-Proj</artifactId>
<name>war-Proj</name>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>xx.xx.xx</groupId>
<artifactId>sub1-Proj</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>xx.xx.xx</groupId>
<artifactId>sub2-Proj</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>