pom文件
1.什么是pom?
POM 是 Project Object Model 的缩写,即项目对象模型。
pom.xml 就是 maven 的配置文件,用以描述项目的各种信息。
2.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"
<modelVersion>4.0.0</modelVersion>
project是pom.xml中描述符的根
moelVersion是指定pom.xml符合那个版本的描述符
maven坐标
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<name></name>
<description></description>
<properties>
<java.version>1.8</java.version>
</properties>
maven中,根据groupId、artifactId、version组合成
groupId:artifactId:version来唯一标识一个jar包。
groupId-团体、组织的标识符
artifactId-单独项目的唯一标识符
version-一个项目的特定版本
name-项目名称
parent
maven支持继承功能,子类可以使用parent指定父pom,继承其配置。
<parent>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
properties
属性列表,定义的属性可以在pom.xml文件中任意处使用,使用方式为${properties}
<project>
...
<properties>
</properties>
...
</project>
依赖配置
denpendencies
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<type></type>
<scope></scope>
<optional></optional>
<exclusions>
<exclusion>
<groupId></groupId>
<artifactId></artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
groupId、artifactId、version与基本配置中的意义一样
type对应packing类型,不使用type标签,maven默认为jar
scope指的是类的路径以及如何限制依赖关系的传递性(compile默认值,依赖关系在所有classpath中都可以用、provided-用于编译和测试、runtime-用于运行和测试、test-仅仅适用于测试编译和执行阶段、optional-表示不需要这个依赖,项目仍能运行)
exclusions-包含要排除的元素,每个排除元素包含一个要排除的依赖关系的groupId和artifactId。
构建配置
plugins
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<extensions>false</extensions>
<inherited>true</inherited>
<configuration>
<classifier>test</classifier>
</configuration>
<dependencies>...</dependencies>
<executions>...</executions>
</plugin>
</plugins>
</build>
groupId、artifacted、version和基本配置中的一样
extensions:值为true或者false,是否加载该插件的扩展名,默认false
inherited:值为true或者false,这个插件配置是否应该适用于继承自这个插件的POM,默认值为true
configuration-个人插件的配置
dependencies:插件本身需要的依赖
executions:执行配置插件的目标执行
参考资料
https://zhuanlan.zhihu.com/p/76874769