- pom文件最基本内容
<?xml version="1.0" encoding="UTF-8"?> <!-- xml: xml标识 -->
<!-- project: pom文件根元素 -->
<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> <!-- modelVersion: 模型版本,根据版本不同模型内容也不同,这里学习4.0.0版本 -->
<groupId>com.pmq.maven</groupId> <!-- 表明创作者身份或组织 -->
<artifactId>maven-basic</artifactId> <!-- 对外发布的软件名称(唯一) -->
<version>1.0-SNAPSHOT</version> <!-- 软件版本号 -->
</project>
- pom的继承
.
|-- my-module
| `-- pom.xml
`-- pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>../my-module</module>
</modules>
</project>
<project>
<modelVersion>4.0.0</modelVersion>
<parent><!-- 使用parent 声明父pom -->
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</parent>
<artifactId>my-module</artifactId>
</project>
- Properties 项目中定义的任何属性引用为变量。
<project>
...
<properties>
<mavenVersion>3.0</mavenVersion><!-- 声明mavenVersion的变量 -->
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${mavenVersion}</version><!-- 变量的使用 -->
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
</dependency>
</dependencies>
...
</project>
- 特殊的变量
project.basedir | The directory that the current project resides in. |
|---|---|
project.baseUri | The directory that the current project resides in, represented as an URI. Since Maven 2.1.0 |
maven.build.timestamp | The timestamp that denotes the start of the build (UTC). Since Maven 2.1.0-M1 |
- 项目模块变量
开头为project.*, 比如
${project.groupId},${project.version},${project.build.sourceDirectory}
一个pom文件中包含
-
<repositories>定义仓库 -
<pluginRepositories>定义插件仓库 -
<dependencies>定义依赖 -
<plugins>定义插件 -
<properties>定义变量 -
<modules>定义模块 -
<reports> -
<reporting> -
<dependencyManagement>定义依赖管理,用于管理依赖版本 -
<distributionManagement> -
可包含:
-
<defaultGoal> -
<resources> -
<testResources> -
<directory> -
<finalName> -
<filters> -
<pluginManagement> -
<plugins>
-