Introduction to Maven POM

POM (Project Object Model, Project Object Model) is the basic unit of work of Maven project, is an XML file, contains the basic information of the project, used to describe how the project is built, declare project dependencies and so on.

When executing a task or goal, Maven will look for the POM in the current directory. It reads the POM, obtains the required configuration information, and then executes the target.

The following configurations can be specified in POM:

  • Project build profile
  • Project dependency
  • Plugin
  • Implementation goals
  • Project version
  • Project Developer List
  • Related mailing list information

Create the POM file pom.xml

Create a pom.xml file in the root directory of the project.
pom.xml:

<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>
    
    <!-- 公司或者组织的唯一标志,并且配置时生成的路径也是由此生成, 如com.companyname.project-group,maven会将该项目打成的jar包放本地路径:/com/companyname/project-group -->
    <groupId>com.companyname.project-group</groupId>

    <!-- 项目的唯一ID,一个groupId下面可能多个项目,就是靠artifactId来区分的 -->
    <artifactId>project-name</artifactId>
 
    <!-- 版本号 -->
    <version>1.0</version>
</project>

All POM files require a project element and three required fields: groupId, artifactId, and version .

  • project is the root tag of the project
  • modelVersion should be set to 4.0.0
  • groupId is the ID of the engineering group
  • artifactId is the identifier of the project, usually the name of the project. groupId and artifactId together define the location of artifact in the warehouse
  • version is the version number of the project. In the artifact warehouse, it is used to distinguish different versions, such as: com.companyname.project-group: project-name: 1.0

Parent (Super) POM

The parent (Super) POM is Maven's default POM. All POMs will inherit from a parent POM (whether or not this parent POM is explicitly defined). The parent POM contains some default settings that can be inherited. Therefore, when Maven finds that it needs to download the dependencies in the POM, it will go to the default warehouse configured in Super POM to download.

Maven uses effective pom to execute related goals. It helps developers to do as little configuration as possible in Pom.xml (Super pom plus the project's own configuration). Of course, these configurations can be rewritten.

Use the following command to view the Super POM default configuration:

mvn help:effective-pom

POM label can refer to "POM Label Encyclopedia"

Published 381 original articles · praised 85 · 80,000 views +

Guess you like

Origin blog.csdn.net/weixin_40763897/article/details/105000022