父项目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>
<groupId>privs.nb.study.maven</groupId>
<artifactId>ParentModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ParentModule</name>
<description>ParentModule parent</description>
<packaging>pom</packaging>
<properties>
<java.version>8</java.version>
</properties>
<modules>
<module>SubModule</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
子项目POM定义
使用parent标签引入parent项目的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>
<groupId>privs.nb.study.maven</groupId>
<artifactId>SubModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SubModule</name>
<description>ParentModule parent</description>
<parent>
<groupId>privs.nb.study.maven</groupId>
<artifactId>ParentModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<java.version>8</java.version>
</properties>
</project>
使用import引入parent项目文件
<?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>
<groupId>privs.nb.study.maven</groupId>
<artifactId>SubModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SubModule</name>
<properties>
<java.version>8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>privs.nb.study.maven</groupId>
<artifactId>ParentModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Parent标签和import的在于使用import时父pom中由dependencyManagement引用的依赖无法引入子项目