pom.xml常用的标签
通常在父pom的标签
<dependencyManagement>
dependencyManagement 和 dependencies区别:
1)Dependencies相对于dependencyManagement,所有生命在dependencies里的依赖都会自动引入,并默认被所有的子项目继承。
2)dependencyManagement里只是声明依赖,并不自动实现引入,因此子项目需要显示的声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。
modules 聚合(或多模块)
为了能一次构建两个(或多个)模块,就需要再创建一个pom.xml来对多个模块进行集中的操作,也就是聚合。
案例
spring boot maven pom依赖
spring-boot-starter-web (pom packaging)-> spring-boot-parent (pom packaging) ->spring-boot-dependencies (pom packaging)
一个百人团队的maven 依赖的架构
module (jar packaging)-> (pom packaging) project -> common-dependencies (pom packaging) 公司级别公共的jar包管理
子pom的常用标签
<parent> 对父pom的依赖。
<distributionManagement> 指定Maven分发构件(deploy)的位置
案例
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build> 用于编译配置。
案例
<build>
<!-- 项目的名字 -->
<finalName>WebMavenDemo</finalName>
<!-- 描述项目中资源的位置 -->
<resources>
<!-- 自定义资源1 -->
<resource>
<!-- 资源目录 -->
<directory>src/main/java</directory>
<!-- 包括哪些文件参与打包 -->
<includes>
<include>**/*.xml</include>
</includes>
<!-- 排除哪些文件不参与打包 -->
<excludes>
<exclude>**/*.txt</exclude>
<exclude>**/*.doc</exclude>
</excludes>
</resource>
</resources>
<!-- 设置构建时候的插件 -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<!-- 源代码编译版本 -->
<source>1.8</source>
<!-- 目标平台编译版本 -->
<target>1.8</target>
</configuration>
</plugin>
<!-- 资源插件(资源的插件) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- war插件(将项目打成war包) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<!-- war包名字 -->
<warName>WebMavenDemo1</warName>
</configuration>
</plugin>
</plugins>
</build>
<profile>
简单说一下,maven的profile可以让我们定义一系列的配置信息,然后指定其激活条件。这样我们就可以定义多个profile,然后每个profile对应不同的激活条件和配置信息,从而达到不同环境使用不同配置信息的目的。
maven依赖冲突
所谓的依赖冲突,举例说明,工程A依赖B和C,但是B和C分别依赖不同版本的D。那么对于工程A来说,到底是依赖了哪个版本的D呢?
解决依赖冲突有2个基本的原则:
短路优先原则。 比如存在如下的两个依赖路径,那么A最终会依赖version2的X版本。
A->B->C->X(version1)
A->D->X(version2)
如果路径长度相同,那么先声明先解析。
dependencyManagement 和 dependencies区别:
https://blog.csdn.net/yuyecsdn/article/details/90229024
maven中的distributionManagement的作用
https://blog.csdn.net/qq_31924435/article/details/53745811
maven pom项目结构
网友评论