POM也包含了目標和插件。在執行任務或目標時,Maven會找到在當前目錄中的POM文件並進行讀取,得到所需要的配置信息,然後執行的目標。部分的配置,可以在POM如下:
project dependencies
plugins
goals
build profiles
project version
developers
mailing list
創建一個POM之前,我們應該先決定項目組(groupId),它的名字(artifactId)和它的版本,因爲這些屬性是用來作唯一標示的。
例子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> <groupId>com.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> </project>
應當指出,應該有一個單一的POM文件爲每個項目。所有的POM文件要求的項目元素和三個必填字段: groupId,artifactId版本。
在庫中的項目符號是:groupId:artifactId:version.
根元素的pom.xml是項目,它有三個主要的子節點:
Node | Description |
groupId | This is an Id of project's group. This is generally unique amongst an organization or a project. For example, a banking group com.company.bank has all bank related projects. |
artifactId | This is an Id of the project.This is generally name of the project. For example, consumer-banking. Along with the groupId, the artifactId defines the artifact's location within the repository. |
version | This is the version of the project.Along with the groupId, It is used within an artifact's repository to separate versions from each other. For example: com.company.bank:consumer-banking:1.0 com.company.bank:consumer-banking:1.1. |