1.文件结构

2.maven仓库
配置阿里云远程仓库
<mirrors><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirrors>
仓库依赖存储地址,windwos的话要使用/
<localRepository>A:/Tools/server/apache-maven-3.6.3/repository</localRepository>
3.maven命令

mvn clean 清空target目录下文件mvn compile 编译成字节码存储只target目录mvn package 打包mvn install 安装到本地仓库
4.maven生命周期
5.maven依赖范围

scope标签表示test时才执行,默认是compile范围
<scope>test</scope>
6.父子项目依赖传递

父项目要以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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>maven-parent</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><!-- 子项目--><module>maven-son</module></modules><name>maven-parent</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target><spring.version>5.3.4</spring.version></properties><!-- dependencyManagement只有被子项目引用才会下载依赖--><dependencyManagement><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency></dependencies></dependencyManagement><build><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --></pluginManagement></build></project>
子项目继承父项目,maven聚合管理,使用父项目的通用依赖与版本
<?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"><parent><artifactId>maven-parent</artifactId><groupId>org.example</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>maven-son</artifactId><name>maven-son</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId></dependency></dependencies><build></build></project>
7.私人仓库
8.排除依赖
这两个项目都依赖common-logging,导致直接冲突,这个情况就需要排除依赖,排序低版本依赖,因为高版本是向下兼容的
<dependency><groupId>commons-beanutils</groupId><artifactId>commons-beanutils</artifactId><version>1.9.4</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.5-FINAL</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency>

传递依赖


