注释很详细,直接上代码
项目结构
内容
父项目 pom.xml
<?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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><!-- 项目信息 --><groupId>com.amoorzheyu</groupId><artifactId>Maven_Study</artifactId><version>1.0-SNAPSHOT</version><!-- 模块信息:子模块 --><modules><module>Maven_Study_1</module><module>Maven_Study_2</module></modules><!-- 父模块打包方式:pom --><packaging>pom</packaging><!-- 编译信息 --><properties><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><!-- 依赖信息:会传递给子模块 --><dependencies><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.3.0</version><!-- 排除依赖:无需版号 --><exclusions><exclusion><groupId>com.mysql</groupId><artifactId>protobuf:protobuf</artifactId></exclusion></exclusions><!-- 依赖范围有4种:provided、compile、runtime、testprovided:在编译和测试时需要,在打包时无需该依赖compile:在编译、测试、打包时需要该依赖runtime:在测试、打包时需要该依赖test:在测试时需要该依赖scope默认为compile--><scope>provided</scope></dependency></dependencies>
</project>
子项目1 pom.xml
<?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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.amoorzheyu</groupId><artifactId>Maven_Study</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>Maven_Study_1</artifactId><properties><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties></project>