Detailed explanation of maven pom file

1. maven official website

maven official website
maven official website pom file detailed link

2. maven pom

1. Directory structure of maven project

The pom file is determined by the maven configuration of a maven project. Generally, the pom file is placed in the root directory of the project or module.
Maven follows conventions more than configurations, and has agreed on the following directory structure:

Table of contents Purpose
${based} Store pom.xml and all subdirectories
${basedir}/src/main/java Project java source code
${basedir}/src/main/resources Project resources, such as property files, springmvc.xml
${basedir}/src/test/java The test class of the project, such as Junit code
${basedir}/src/test/resources Resources for testing
${basedir}/src/main/scripts Directory of project script source code
${basedir}/src/main/webapp/WEB-INF Web application file directory, web project information, such as storing web.xml, local pictures, and jsp view pages
${basedir}/target/classes Compile output directory
${basedir}/target/site Directory of generated documents. You can view the project documents through index.html
${basedir}/target/test-classes Test compilation output directory
Test.java Maven will only automatically run test classes that comply with this naming rule
~/.m2/repository or under the conf subdirectory of the Maven installation directory Maven's default local warehouse directory location

2. Root element and necessary configuration

<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>
    <!-- 公司或者组织的唯一标志,也是打包成jar包路径的依据 -->
    <!-- 例如com.companyname.project-group,maven打包jar包的路径:/com/companyname/project-group -->
    <groupId>com.companyname.project-group</groupId>
 
    <!-- 项目的唯一ID,一个groupId下面可能多个项目,就是靠artifactId来区分的 -->
    <artifactId>project</artifactId>
 
    <!-- 项目当前版本,格式为:主版本.次版本.增量版本-限定版本号 -->
    <version>1.0</version>
 
    <!--项目产生的构件类型,包括jar、war、ear、pom等 -->
    <packaging>jar</packaging>
</project>

Project is the root element of the pom file. There are important elements such as modelVersion, groupId, artifactId, version, and packaging under project. Among them, the three elements groupId, artifactId, and version are used to define the coordinates of a project. That is to say, in a maven warehouse, there can only be one project with the same set of groupId, artifactId, and version.

  • project: the root element of the entire pom configuration file, all configurations are written in the project element;
  • modelVersion: specifies the version of the current POM model. For Maven2 and Maven 3, it can only be 4.0.0;
  • groupId: This is the identification of the project group. It is usually unique within an organization or project.
  • artifactId: This is the identifier of the project, usually the name of the project. It is unique within a project group.
  • version: This is the version number of the project, used to distinguish different versions of the same artifact.
  • Packaging: This is the component type generated by the project, that is, the suffix name of the output file packaged by the project through maven, including jar, war, ear, pom, etc.

3. Parent project and parent element

    <!--父项目的坐标,坐标包括group ID,artifact ID和version。 -->
    <!--如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值 -->
    <parent>
 
        <!--被继承的父项目的构件标识符 -->
        <artifactId>com.companyname.project-group</artifactId>
        <!--被继承的父项目的全球唯一标识符 -->
        <groupId>base-project</groupId>
        <!--被继承的父项目的版本 -->
        <version>1.0.1-RELEASE</version>
 
        <!-- 父项目的pom.xml文件的相对路径,默认值是../pom.xml。 -->
        <!-- 寻找父项目的pom:构建当前项目的地方--)relativePath指定的位置--)本地仓库--)远程仓库 -->
        <relativePath>../pom.xml</relativePath>
    </parent>

All poms inherit from a parent pom (Super POM). The parent pom contains some default settings that can be inherited. If these elements are not set in the project's pom, the settings in the parent pom will be used. For example, Super POM is configured with a default repository http://repo1.maven.org/maven2, so even if there is no repository configured in the project's POM, you can go to this default repository to download dependencies. In fact, the principle that maven pom file convention is greater than configuration is achieved by predefining some configuration information in Super POM.

Maven使用effective pom(Super pom加上工程自己的配置)来执行相关的目标,它帮助开发者在pom.xml中做尽可能少的配置。当然,这些配置也可以被重写。

parent元素可以指定父pom。用户可以通过增加parent元素来自定义一个父pom,从而继承该pom的配置。parent元素中包含一些子元素,用来定位父项目和父项目的pom文件位置。

parent: used to specify the parent project;
groupId: the child element of parent, the groupId of the parent project, used to locate the parent project;
artifactId : The child element of parent, the artifactId of the parent project, used to locate the parent project;
version: The child element of parent, the version of the parent project, used to locate the parent project;
relativePath: child element of parent, used to locate the location of the parent project pom file

4. Information required for project construction

    <!--构建项目需要的信息 -->
    <build>
        <!--------------------- 路径管理(在遵循约定大于配置原则下,不需要配置) --------------------->
        <!--项目源码目录,当构建项目的时候,构建系统会编译目录里的源码。该路径是相对于pom.xml的相对路径。 -->
        <sourceDirectory />
        <!--该元素设置了项目单元测试使用的源码目录。该路径是相对于pom.xml的相对路径 -->
        <testSourceDirectory />
        <!--被编译过的应用程序class文件存放的目录。 -->
        <outputDirectory />
        <!--被编译过的测试class文件存放的目录。 -->
        <testOutputDirectory />        
        <!--项目脚本源码目录,该目录下的内容,会直接被拷贝到输出目录,因为脚本是被解释的,而不是被编译的 -->
        <scriptSourceDirectory />
 
        <!--------------------- 资源管理 --------------------->
        <!--这个元素描述了项目相关的所有资源路径列表,例如和项目相关的属性文件,这些资源被包含在最终的打包文件里。 -->
        <resources>
            <!--这个元素描述了项目相关或测试相关的所有资源路径 -->
            <resource>
                <!-- 描述了资源的目标输出路径。该路径是相对于target/classes的路径 -->
                <!-- 如果是想要把资源直接放在target/classes下,不需要配置该元素 -->
                <targetPath />
                <!--是否使用参数值代替参数名。参数值取自文件里配置的属性,文件在filters元素里列出。 -->
                <filtering />
                <!--描述存放资源的目录,该路径相对POM路径 -->
                <directory />
                <!--包含的模式列表,例如**/*.xml,只有符合条件的资源文件才会在打包的时候被放入到输出路径中 -->
                <includes />
                <!--排除的模式列表,例如**/*.xml,符合的资源文件不会在打包的时候会被过滤掉 -->
                <excludes />
            </resource>
        </resources>
        <!--这个元素描述了单元测试相关的所有资源路径,例如和单元测试相关的属性文件。 -->
        <testResources>
            <!--这个元素描述了测试相关的所有资源路径,子元素说明参考build/resources/resource元素的说明 -->
            <testResource>
                <targetPath />
                <filtering />
                <directory />
                <includes />
                <excludes />
            </testResource>
        </testResources>
 
        <!--------------------- 插件管理 --------------------->
        <!-- 子项目可以引用的默认插件信息。pluginManagement中的插件直到被引用时才会被解析或绑定到生命周期 -->
        <!-- 这里只是做了声明,并没有真正的引入。给定插件的任何本地配置都会覆盖这里的配置-->
        <pluginManagement>
            <!-- 可使用的插件列表 -->
            <plugins>
                <!--plugin元素包含描述插件所需要的信息。 -->
                <plugin>
                    <!--插件在仓库里的group ID -->
                    <groupId />
                    <!--插件在仓库里的artifact ID -->
                    <artifactId />
                    <!--被使用的插件的版本(或版本范围) -->
                    <version />
                    <!-- 是否从该插件下载Maven扩展(例如打包和类型处理器) -->
                    <!-- 由于性能原因,只有在真需要下载时,该元素才被设置成enabled -->
                    <extensions />
                    <!--在构建生命周期中执行一组目标的配置。每个目标可能有不同的配置。 -->
                    <executions>
                        <!--execution元素包含了插件执行需要的信息 -->
                        <execution>
                            <!--执行目标的标识符,用于标识构建过程中的目标,或者匹配继承过程中需要合并的执行目标 -->
                            <id />
                            <!--绑定了目标的构建生命周期阶段,如果省略,目标会被绑定到源数据里配置的默认阶段 -->
                            <phase />
                            <!--配置的执行目标 -->
                            <goals />
                            <!--配置是否被传播到子POM -->
                            <inherited />
                            <!--作为DOM对象的配置 -->
                            <configuration />
                        </execution>
                    </executions>
                    <!--项目引入插件所需要的额外依赖 -->
                    <dependencies>
                        <!--参见dependencies/dependency元素 -->
                        <dependency>
                            ......
                        </dependency>
                    </dependencies>
                    <!--任何配置是否被传播到子项目 -->
                    <inherited />
                    <!--作为DOM对象的配置 -->
                    <configuration />
                </plugin>
            </plugins>
        </pluginManagement>
        <!--使用的插件列表 -->
        <plugins>
            <!--参见build/pluginManagement/plugins/plugin元素 -->
            <plugin>
                <groupId />
                <artifactId />
                <version />
                <extensions />
                <executions>
                    <execution>
                        <id />
                        <phase />
                        <goals />
                        <inherited />
                        <configuration />
                    </execution>
                </executions>
                <dependencies>
                    <!--参见dependencies/dependency元素 -->
                    <dependency>
                        ......
                    </dependency>
                </dependencies>
                <goals />
                <inherited />
                <configuration />
            </plugin>
        </plugins>
 
        <!--------------------- 构建扩展 --------------------->
        <!--使用来自其他项目的一系列构建扩展 -->
        <extensions>
            <!--每个extension描述一个会使用到其构建扩展的一个项目,extension的子元素是项目的坐标 -->
            <extension>
                <!--项目坐标三元素:groupId + artifactId + version -->
                <groupId />
                <artifactId />
                <version />
            </extension>
        </extensions>
 
        <!--------------------- 其他配置 --------------------->
        <!--当项目没有规定目标(Maven2 叫做阶段)时的默认值 -->
        <defaultGoal />
        <!--构建产生的所有文件存放的目录 -->
        <directory />
        <!--产生的构件的文件名,默认值是${artifactId}-${version}。 -->
        <finalName />
        <!--当filtering开关打开时,使用到的过滤器属性文件列表 -->
        <filters />
    </build>

The build tag defines the information needed to build the project. This part of information is very important for customized project construction. Here we will briefly explain the classification according to the characteristics of the sub-elements of build.

4.1. Path management

       <!--------------------- 路径管理(在遵循约定大于配置原则下,不需要配置) --------------------->
        <!--项目源码目录,当构建项目的时候,构建系统会编译目录里的源码。该路径是相对于pom.xml的相对路径。 -->
        <sourceDirectory />
        <!--该元素设置了项目单元测试使用的源码目录。该路径是相对于pom.xml的相对路径 -->
        <testSourceDirectory />
        <!--被编译过的应用程序class文件存放的目录。 -->
        <outputDirectory />
        <!--被编译过的测试class文件存放的目录。 -->
        <testOutputDirectory />        
        <!--项目脚本源码目录,该目录下的内容,会直接被拷贝到输出目录,因为脚本是被解释的,而不是被编译的 -->
        <scriptSourceDirectory />

Path management defines the output paths of various source codes and compilation results. If you follow maven's default path convention, several elements here do not need to be configured. These elements include:

sourceDirectory: project source code directory, which defines the relative path relative to the pom file;
testSourceDirectory: project unit test source code directory, which also defines the relative path relative to the pom file ;
outputDirectory: the directory where the compiled application class files are stored, which is also a relative path to the pom file;
testOutoutDIrectory: the compiled test The directory where the class file is stored is also a relative path relative to the pom file;
scriptSourceDirectory: the project script source code directory, which is also a relative path relative to the pom file. Since the script is an interpreted language, the contents of this directory will be copied directly to the output directory without compilation.

4.2. Resource management

        <!--------------------- 资源管理 --------------------->
        <!--这个元素描述了项目相关的所有资源路径列表,例如和项目相关的属性文件,这些资源被包含在最终的打包文件里。 -->
        <resources>
            <!--这个元素描述了项目相关或测试相关的所有资源路径 -->
            <resource>
                <!-- 描述了资源的目标输出路径。该路径是相对于target/classes的路径 -->
                <!-- 如果是想要把资源直接放在target/classes下,不需要配置该元素 -->
                <targetPath />
                <!--是否使用参数值代替参数名。参数值取自文件里配置的属性,文件在filters元素里列出 -->
                <filtering />
                <!--描述打包前的资源存放的目录,该路径相对POM路径 -->
                <directory />
                <!--包含的模式列表,例如**/*.xml,只有符合条件的资源文件才会在打包的时候被放入到输出路径中 -->
                <includes />
                <!--排除的模式列表,例如**/*.xml,符合的资源文件不会在打包的时候会被过滤掉 -->
                <excludes />
            </resource>
        </resources>
        <!--这个元素描述了单元测试相关的所有资源路径,例如和单元测试相关的属性文件。 -->
        <testResources>
            <!--这个元素描述了测试相关的所有资源路径,子元素说明参考build/resources/resource元素的说明 -->
            <testResource>
                <targetPath />
                <filtering />
                <directory />
                <includes />
                <excludes />
            </testResource>
        </testResources>

The elements here are mainly for the management of application resource resources and unit test part resource resources. The two resources are managed through resource tags and testResource tags respectively. The optional child elements of both label elements are the same. Child elements include:

  • targetPath: describes the target output path of the resource, which is relative to target/classes;
  • filtering: Filter the parameter values ​​in the file. The files that need to be filtered are specified in filter;
  • Directory: Describes the storage path of resources before packaging. This path is relative to the directory where the pom file is located;
  • includes: A list of included patterns, such as **/*.xml. Only resource files that meet the conditions will be placed in the output path during packaging;
  • excludes: Excluded pattern list, such as **/*.xml, matching resource files will not be filtered out during packaging.

4.3. Plug-in management

There are two elements related to plug-in management, including pluginManagement and plugins. There are sub-element plugins in pluginManagement. The difference between it and the direct sub-element plugins under project is that pluginManagement is mainly used to declare the default plug-in information that sub-projects can reference. These plug-ins will not be introduced if they are only written in pluginManagement. The plug-ins defined in the direct sub-element plugins under project are the plug-ins that really need to be introduced in this project.

        <!--------------------- 插件管理 --------------------->
        <!-- 子项目可以引用的默认插件信息。pluginManagement中的插件直到被引用时才会被解析或绑定到生命周期 -->
        <!-- 这里只是做了声明,并没有真正的引入。给定插件的任何本地配置都会覆盖这里的配置-->
        <pluginManagement>
            <!-- 可使用的插件列表 -->
            <plugins>
                <!--plugin元素包含描述插件所需要的信息。 -->
                <plugin>
                    <!--插件定位坐标三元素:groupId + artifactId + version -->
                    <groupId />
                    <artifactId />
                    <version />
                    <!-- 是否使用这个插件的Maven扩展(extensions),默认为false -->
                    <!-- 由于性能原因,只有在真需要下载时,该元素才被设置成enabled -->
                    <extensions />
                    <!--在构建生命周期中执行一组目标的配置。每个目标可能有不同的配置。 -->
                    <executions>
                        <!--execution元素包含了插件执行需要的信息 -->
                        <execution>
                            <!--执行目标的标识符,用于标识构建过程中的目标,或者匹配继承过程中需要合并的执行目标 -->
                            <id />
                            <!--绑定了目标的构建生命周期阶段,如果省略,目标会被绑定到源数据里配置的默认阶段 -->
                            <phase />
                            <!--配置的执行目标 -->
                            <goals />
                            <!--配置是否被传播到子POM -->
                            <inherited />
                            <!--作为DOM对象的配置 -->
                            <configuration />
                        </execution>
                    </executions>
                    <!--项目引入插件所需要的额外依赖,参见dependencies元素 -->
                    <dependencies>
                            ......
                    </dependencies>
                    <!--任何配置是否被传播到子项目 -->
                    <inherited />
                    <!--作为DOM对象的配置 -->
                    <configuration />
                </plugin>
            </plugins>
        </pluginManagement>
        <!--使用的插件列表,这里是真正的引入插件。参见build/pluginManagement/plugins元素 -->
        <plugins>
            ......
        </plugins>

4.4. Build extensions

extensions is a list of projects used in this build that will be included in the classpath when the build is run. These projects enable extensions to the build process and enable active plugins to make changes to the build lifecycle. Simply put, extensions are artifacts that are activated during build time. The extension doesn't need to actually do anything and doesn't include Mojo. Therefore, extensions are great for specifying one of multiple implementations of a common plugin interface.

        <!--------------------- 构建扩展 --------------------->
        <!--使用来自其他项目的一系列构建扩展 -->
        <extensions>
            <!--每个extension描述一个会使用到其构建扩展的一个项目,extension的子元素是项目的坐标 -->
            <extension>
                <!--项目坐标三元素:groupId + artifactId + version -->
                <groupId />
                <artifactId />
                <version />
            </extension>
        </extensions>

4.5. Other configurations

There are also some configurations in the build, as follows:

        <!--------------------- 其他配置 --------------------->
        <!--当项目没有规定目标(Maven2 叫做阶段)时的默认值 -->
        <defaultGoal />
        <!--构建产生的所有文件存放的目录 -->
        <directory />
        <!--产生的构件的文件名,默认值是${artifactId}-${version}。 -->
        <finalName />
        <!--当filtering开关打开时,使用到的过滤器属性文件列表 -->
        <filters />

5. Project dependency related information

Dependencies are declared in the pom file through dependencyManagement, and dependencies are managed through the dependencies element. The sub-element under dependencyManagement has only one direct sub-element, dependency, and its configuration is completely consistent with the dependencies sub-element; while there is only one direct sub-element under dependencies: dependency. A dependency child element represents a dependent project.

    <!--该元素描述了项目相关的所有依赖。 这些依赖自动从项目定义的仓库中下载 -->
    <dependencies>
        <dependency>
            <!------------------- 依赖坐标 ------------------->
            <!--依赖项目的坐标三元素:groupId + artifactId + version -->
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-artifact</artifactId>
            <version>3.8.1</version>
 
            <!------------------- 依赖类型 ------------------->
            <!-- 依赖类型,默认是jar。通常表示依赖文件的扩展名,但有例外。一个类型可以被映射成另外一个扩展名或分类器 -->
            <!-- 类型经常和使用的打包方式对应,尽管这也有例外,一些类型的例子:jar,war,ejb-client和test-jar -->
            <!-- 如果设置extensions为true,就可以在plugin里定义新的类型 -->
            <type>jar</type>
            <!-- 依赖的分类器。分类器可以区分属于同一个POM,但不同构建方式的构件。分类器名被附加到文件名的版本号后面 -->
            <!-- 如果想将项目构建成两个单独的JAR,分别使用Java 4和6编译器,就可以使用分类器来生成两个单独的JAR构件 -->
            <classifier></classifier>
 
            <!------------------- 依赖传递 ------------------->
            <!--依赖排除,即告诉maven只依赖指定的项目,不依赖该项目的这些依赖。此元素主要用于解决版本冲突问题 -->
            <exclusions>
                <exclusion>
                    <artifactId>spring-core</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
            <!-- 可选依赖,用于阻断依赖的传递性。如果在项目B中把C依赖声明为可选,那么依赖B的项目中无法使用C依赖 -->
            <optional>true</optional>
            
            <!------------------- 依赖范围 ------------------->
            <!--依赖范围。在项目发布过程中,帮助决定哪些构件被包括进来
                - compile:默认范围,用于编译;  - provided:类似于编译,但支持jdk或者容器提供,类似于classpath 
                - runtime: 在执行时需要使用;    - systemPath: 仅用于范围为system。提供相应的路径 
                - test: 用于test任务时使用;    - system: 需要外在提供相应的元素。通过systemPath来取得 
                - optional: 当项目自身被依赖时,标注依赖是否传递。用于连续依赖时使用 -->
            <scope>test</scope>
            <!-- 该元素为依赖规定了文件系统上的路径。仅供scope设置system时使用。但是不推荐使用这个元素 -->
            <!-- 不推荐使用绝对路径,如果必须要用,推荐使用属性匹配绝对路径,例如${java.home} -->
            <systemPath></systemPath>
        </dependency>
    </dependencies>
 
    <!-- 继承自该项目的所有子项目的默认依赖信息,这部分的依赖信息不会被立即解析。 -->
    <!-- 当子项目声明一个依赖,如果group ID和artifact ID以外的一些信息没有描述,则使用这里的依赖信息 -->
    <dependencyManagement>
        <dependencies>
            <!--参见dependencies/dependency元素 -->
            <dependency>
                ......
            </dependency>
        </dependencies>
    </dependencyManagement>

Here we also briefly classify the sub-elements of dependency based on the role of the elements. Let’s take a look at the sub-elements of dependency by category:

5.1. Dependence on coordinates

依然是通过groupId + artifactId + version来在仓库中定位一个项目:

groupId: the child element of parent, the groupId of the parent project, used to locate the parent project;
artifactId: the child element of parent, the artifactId of the parent project, used to locate the parent project;
version: the child element of parent, the version of the parent project, used to locate the parent project;

5.2. Dependency type

这个分类主要包括两个元素,分别是依赖类型和依赖的分类器。同一个项目,即使打包成同一种类型,也可以有多个文件同时存在,因为它们的分类器可能是不同的。

type: dependency type, the default is jar. Usually means depending on the file extension, but there are exceptions. A type can be mapped to another extension or classifier. The type usually corresponds to the packaging method used, although there are exceptions to this, some examples of types: jar, war, ejb-client and test-jar. If you set extensions to true, you can define new types in the plugin.
classifier: dependent classifier. The classifier can distinguish components that belong to the same POM but are built in different ways. The classifier name is appended to the version number of the file name. If you want to build the project into two separate JARs, using the Java 4 and 6 compilers, you can use the classifier to generate two separate JAR artifacts

5.3. Dependency transfer

依赖传递相关的子元素主要有两个,用于依赖排除的exclusions和设置依赖是否可选的optional。

exclusions: exclude some dependencies in the project, that is, project A depends on project B indicated by the dependency, but does not depend on these dependencies in project B;
optional: optional Optional dependency is used to block the transitivity of dependencies, that is, this project will not rely on dependencies with optional set to true in the parent project.

5.4. Dependence scope

There are some other elements:

  • scope: dependency scope. During the project release process, help decide which components are included
    - compile: default scope, used for compilation; - provided: similar to compilation, but supports jdk or container provision, similar to classpath< /span> - Optional: When the project itself is dependent, mark whether the dependency is passed. Used when using continuous dependencies - test: used when used for test tasks; - system: The corresponding elements need to be provided externally and obtained through systemPath
    - runtime: needs to be used during execution; - systemPath: only used when the scope is system, providing the corresponding path

  • systemPath: This element specifies the absolute path on the file system for the dependency. Only used when scope is set to system. Use of this element is deprecated. It is not recommended to use absolute paths. If you must use them, it is recommended to use attributes to match absolute paths, such as ${java.home}

6. Generate document-related elements

    <!--项目的名称, Maven生成文档使用 -->
    <name>project-maven</name>
 
    <!--项目主页的URL, Maven生成文档使用 -->
    <url>http://123.a.b/nsnxs</url>
 
    <!-- 项目的详细描述, Maven生成文档使用。当这个元素能够用HTML格式描述时,不鼓励使用纯文本描述 -->
    <!--如果你需要修改生成的web站点的索引页面,你应该修改你自己的索引页文件,而不是调整这里的文档 -->
    <description>Description of this maven project</description>

Note: Maven can generate project-related documents through the mvn site command.

Elements related to generated documents, including name, url, and description.

  • name: project name, maven will use the project name to generate documents;
  • url: The address of the project homepage, used when maven generates documents.
  • description: Project description. If HTML format can be used for description, plain text description is not recommended.

7. Remote warehouse list

The configuration of the remote warehouse list, including the remote warehouse configuration of dependencies and extensions, and the remote warehouse configuration of the plug-in. If the local repository cannot be found, maven downloads dependencies, extensions and plug-ins from the remote repository configured here.

What needs to be noted is the difference between release and snapshot. Release is a stable version. Once released, it will not be modified. If you want to release the modified project, you can only upgrade the project version before releasing it; snapshot is unstable, and the version of a snapshot can continue to change. During the development period of the project, snapshots are generally used, which is more convenient for frequent code updates; once it is released to the outside, or the development is basically completed, and code iterations are no longer frequent, it is recommended to use release.

    <!--发现依赖和扩展的远程仓库列表。 -->
    <repositories>
        <!--包含需要连接到远程仓库的信息 -->
        <repository>
            <!--如何处理远程仓库里发布版本的下载 -->
            <releases>
                <!--值为true或者false,表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
                <enabled />
                <!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳 -->
                <!--选项:always,daily(默认),interval:X(X单位为分钟),或者never。 -->
                <updatePolicy />
                <!--当Maven验证构件校验文件失败时该怎么做。选项:ignore,fail,或者warn -->
                <checksumPolicy />
            </releases>
            <!-- 如何处理远程仓库里快照版本的下载 -->
            <!-- 有了releases和snapshots这两组配置,就可以在每个单独的仓库中,为每种类型的构件采取不同的策略 -->
            <snapshots>
                <enabled />
                <updatePolicy />
                <checksumPolicy />
            </snapshots>
 
            <!--远程仓库唯一标识符。可以用来匹配在settings.xml文件里配置的远程仓库 -->
            <id>nanxs-repository-proxy</id>
            <!--远程仓库名称 -->
            <name>nanxs-repository-proxy</name>
            <!--远程仓库URL,按protocol://hostname/path形式 -->
            <url>http://192.168.1.169:9999/repository/</url>
            <!-- 用于定位和排序构件的仓库布局类型。可以是default或者legacy -->
            <layout>default</layout>
        </repository>
    </repositories>
    
    <!--发现插件的远程仓库列表,这些插件用于构建和报表 -->
    <pluginRepositories>
        <!--包含需要连接到远程插件仓库的信息。参见repositories/repository元素 -->
        <pluginRepository>
            ......
        </pluginRepository>
    </pluginRepositories>

8. Elements related to project distribution information

    <!--项目分发信息,在执行mvn deploy后表示要发布的位置。用于把网站部署到远程服务器或者把构件部署到远程仓库 -->
    <distributionManagement>
        <!--部署项目产生的构件到远程仓库需要的信息 -->
        <repository>
            <!-- 是分配给快照一个唯一的版本号 -->
            <uniqueVersion />
            <!-- 其他配置参见repositories/repository元素 -->
            <id>nanxs-maven2</id>
            <name>nanxsmaven2</name>
            <url>file://${basedir}/target/deploy</url>
            <layout />
        </repository>
        <!--构件的快照部署的仓库。默认部署到distributionManagement/repository元素配置的仓库 -->
        <snapshotRepository>
            <uniqueVersion />
            <id>nanxs-maven2</id>
            <name>Nanxs-maven2 Snapshot Repository</name>
            <url>scp://svn.baidu.com/nanxs:/usr/local/maven-snapshot</url>
            <layout />
        </snapshotRepository>
        <!--部署项目的网站需要的信息 -->
        <site>
            <!--部署位置的唯一标识符,用来匹配站点和settings.xml文件里的配置 -->
            <id>nanxs-site</id>
            <!--部署位置的名称 -->
            <name>business api website</name>
            <!--部署位置的URL,按protocol://hostname/path形式 -->
            <url>scp://svn.baidu.com/nanxs:/var/www/localhost/nanxs-web</url>
        </site>
        <!--项目下载页面的URL。如果没有该元素,用户应该参考主页 -->
        <!--本元素是为了帮助定位那些不在仓库里的构件(license限制) -->
        <downloadUrl />
        <!--如果构件有了新的group ID和artifact ID(构件移到了新的位置),这里列出构件的重定位信息 -->
        <relocation>
            <!--构件新的group ID -->
            <groupId />
            <!--构件新的artifact ID -->
            <artifactId />
            <!--构件新的版本号 -->
            <version />
            <!--显示给用户的,关于移动的额外信息,例如原因 -->
            <message />
        </relocation>
        <!-- 给出该构件在远程仓库的状态。本地项目中不能设置该元素,因为这是工具自动更新的 -->
        <!-- 有效的值有:none(默认),converted(仓库管理员从 Maven 1 POM转换过来),
            partner(直接从伙伴Maven 2仓库同步过来),deployed(从Maven 2实例部署),
            verified(被核实时正确的和最终的) -->
        <status />
    </distributionManagement>

The relevant configuration of project distribution information is set in distributionManagement. The settings include:

  • repository and snapshotRepository: the remote repository where the build/snapshot build and deployment generated by the project is carried out. If snapshotRepository is not configured, the snapshot will also be deployed to the repository;
  • site: Information required for the website where the project is deployed;
  • downloadUrl: The URL of the project download page, which is provided for builds that are not in the warehouse;
  • Relocation: If the component has a new group ID and artifact ID (moved to a new location), the new information about the component is listed here;
  • status: gives the status of the component in the remote warehouse. This element cannot be set in the local project. This is automatically updated by the tool.

9. Report specifications

The report specification describes some configurations used when using the mvn site command.

    <!-- 该元素描述使用报表插件产生报表的规范 -->
    <!-- 当用户执行"mvn site",这些报表就会运行,在页面导航栏能看到所有报表的链接 -->
    <reporting>
        <!--网站是否排除默认的报表。这包括"项目信息"菜单中的报表。 -->
        <excludeDefaults />
        <!--所有产生的报表存放到哪里。默认值是${project.build.directory}/site。 -->
        <outputDirectory />
        <!--使用的报表插件和他们的配置。 -->
        <plugins>
            <!--plugin元素包含描述报表插件需要的信息 -->
            <plugin>
                <!--报表插件定位:groupId + artifactId + version -->
                <groupId />
                <artifactId />
                <version />
 
                <!--任何配置是否被传播到子项目 -->
                <inherited />
                <!--报表插件的配置 -->
                <configuration />
                <!-- 一组报表的多重规范,每个规范可能有不同的配置。一个规范(报表集)对应一个执行目标 -->
                <!-- 例如,有1~9这9个报表。1,2构成A报表集,对应一个执行目标;2,5构成B报表集,对应另一个执行目标 -->
                <reportSets>
                    <!--表示报表的一个集合,以及产生该集合的配置 -->
                    <reportSet>
                        <!--报表集合的唯一标识符,POM继承时用到 -->
                        <id />
                        <!--产生报表集合时,被使用的报表的配置 -->
                        <configuration />
                        <!--配置是否被继承到子POMs -->
                        <inherited />
                        <!--这个集合里使用到哪些报表 -->
                        <reports />
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>

10. Profile configuration

    <!--在列的项目构建profile,如果被激活,会修改构建处理 -->
    <profiles>
        <!--根据环境参数或命令行参数激活某个构建处理 -->
        <profile>
            <!--构建配置的唯一标识符。即用于命令行激活,也用于在继承时合并具有相同标识符的profile。 -->
            <id />
            <!--自动触发profile的条件逻辑。Activation是profile的开启钥匙,profile的力量来自于它 -->
            <!-- 能够在某些特定的环境中自动使用某些特定的值;这些环境通过activation元素指定。activation元素并不是激活profile的唯一方式 -->
            <activation>
                <!--profile默认是否激活的标志 -->
                <activeByDefault />
                <!--当匹配的jdk被检测到,profile被激活。例如,1.4激活JDK1.4,1.4.0_2,而!1.4激活所有版本不是以1.4开头的JDK -->
                <jdk />
                <!--当匹配的操作系统属性被检测到,profile被激活。os元素可以定义一些操作系统相关的属性。 -->
                <os>
                    <!--激活profile的操作系统的名字 -->
                    <name>Windows XP</name>
                    <!--激活profile的操作系统所属家族(如 'windows') -->
                    <family>Windows</family>
                    <!--激活profile的操作系统体系结构 -->
                    <arch>x86</arch>
                    <!--激活profile的操作系统版本 -->
                    <version>5.1.2600</version>
                </os>
                <!--如果Maven检测到某一个属性(其值可以在POM中通过${名称}引用),其拥有对应的名称和值,Profile就会被激活 -->
                <!--如果值字段是空的,那么存在属性名称字段就会激活profile,否则按区分大小写方式匹配属性值字段 -->
                <property>
                    <!--激活profile的属性的名称 -->
                    <name>mavenVersion</name>
                    <!--激活profile的属性的值 -->
                    <value>2.0.3</value>
                </property>
                <!--提供一个文件名,通过检测该文件的存在或不存在来激活profile。missing检查文件是否存在,如果不存在则激活profile -->
                <!--另一方面,exists则会检查文件是否存在,如果存在则激活profile -->
                <file>
                    <!--如果指定的文件存在,则激活profile。 -->
                    <exists>/usr/local/abcd/abcd-home/jobs/maven-guide-zh-to-production/workspace/
                    </exists>
                    <!--如果指定的文件不存在,则激活profile。 -->
                    <missing>/usr/local/abcd/abcd-home/jobs/maven-guide-zh-to-production/workspace/
                    </missing>
                </file>
            </activation>
 
            <!--构建项目所需要的信息。参见build元素 -->
            <build />
            <!--发现依赖和扩展的远程仓库列表。详情参见repositories元素 -->
            <repositories />
            <!--发现插件的远程仓库列表,这些插件用于构建和报表。详情参见pluginRepositories元素 -->
            <pluginRepositories />
            <!--该元素描述了项目相关的所有依赖。 详细配置参见dependencies -->
            <dependencies />
            <!--该元素包括使用报表插件产生报表的规范。当用户执行"mvn site",这些报表就会运行。在页面导航栏能看到所有报表的链接。参见reporting元素 -->
            <reporting />
            <!--参见dependencyManagement元素 -->
            <dependencyManagement />
            <!--参见distributionManagement元素 -->
            <distributionManagement />
 
            <!--不赞成使用. 现在Maven忽略该元素. -->
            <reports />
            <!--模块(有时称作子项目) 被构建成项目的一部分。列出的每个模块元素是指向该模块的目录的相对路径 -->
            <modules />
            <!--参见properties元素 -->
            <properties />
        </profile>
    </profiles>

11. Mailing list and continuous integration configuration

    <!--项目持续集成信息 -->
    <ciManagement>
        <!--持续集成系统的名字,例如continuum -->
        <system />
        <!--该项目使用的持续集成系统的URL(如果持续集成系统有web接口的话)。 -->
        <url />
        <!--构建完成时,需要通知的开发者/用户的配置项。包括被通知者信息和通知条件(错误,失败,成功,警告) -->
        <notifiers>
            <!--配置一种方式,当构建中断时,以该方式通知用户/开发者 -->
            <notifier>
                <!--传送通知的途径 -->
                <type />
                <!--发生错误时是否通知 -->
                <sendOnError />
                <!--构建失败时是否通知 -->
                <sendOnFailure />
                <!--构建成功时是否通知 -->
                <sendOnSuccess />
                <!--发生警告时是否通知 -->
                <sendOnWarning />
                <!--不赞成使用。通知发送到哪里 -->
                <address />
                <!--扩展配置项 -->
                <configuration />
            </notifier>
        </notifiers>
    </ciManagement>
 
    <!--项目相关邮件列表信息 -->
    <mailingLists>
        <!--该元素描述了项目相关的所有邮件列表。自动产生的网站引用这些信息。 -->
        <mailingList>
            <!--邮件的名称 -->
            <name>Demo</name>
            <!--发送邮件的地址或链接,如果是邮件地址,创建文档时,mailto: 链接会被自动创建 -->
            <post>[email protected]</post>
            <!--订阅邮件的地址或链接,如果是邮件地址,创建文档时,mailto: 链接会被自动创建 -->
            <subscribe>[email protected]</subscribe>
            <!--取消订阅邮件的地址或链接,如果是邮件地址,创建文档时,mailto: 链接会被自动创建 -->
            <unsubscribe>[email protected]</unsubscribe>
            <!--你可以浏览邮件信息的URL -->
            <archive>http:/a.b.c/nanxs/demo/dev/</archive>
        </mailingList>
    </mailingLists>

12. Descriptive information of the project

    <!--项目的问题管理系统(Bugzilla, Jira, Scarab,或任何你喜欢的问题管理系统)的名称和URL -->
    <issueManagement>
        <!--问题管理系统(例如jira)的名字, -->
        <system>jira</system>
        <!--该项目使用的问题管理系统的URL -->
        <url>http://jira.baidu.com/nanxs</url>
    </issueManagement>
 
    <!--项目创建年份,4位数字。当产生版权信息时需要使用这个值。 -->
    <inceptionYear />
 
    <!--项目开发者列表 -->
    <developers>
        <!--某个项目开发者的信息 -->
        <developer>
            <!--SCM里项目开发者的唯一标识符 -->
            <id>HELLO WORLD</id>
            <!--项目开发者的全名 -->
            <name>nanxs</name>
            <!--项目开发者的email -->
            <email>[email protected]</email>
            <!--项目开发者的主页的URL -->
            <url />
            <!--项目开发者在项目中扮演的角色,角色元素描述了各种角色 -->
            <roles>
                <role>Project Manager</role>
                <role>Architect</role>
            </roles>
            <!--项目开发者所属组织 -->
            <organization>demo</organization>
            <!--项目开发者所属组织的URL -->
            <organizationUrl>http://a.b.com/nanxs</organizationUrl>
            <!--项目开发者属性,如即时消息如何处理等 -->
            <properties>
                <dept>No</dept>
            </properties>
            <!--项目开发者所在时区, -11到12范围内的整数。 -->
            <timezone>-5</timezone>
        </developer>
    </developers>
 
    <!--项目的其他贡献者列表 -->
    <contributors>
        <!--项目的其他贡献者。参见developers/developer元素 -->
        <contributor>
            <name />
            <email />
            <url />
            <organization />
            <organizationUrl />
            <roles />
            <timezone />
            <properties />
        </contributor>
    </contributors>
 
    <!--该元素描述了项目所有License列表。 应该只列出该项目的license列表,不要列出依赖项目的license列表 -->
    <!--如果列出多个license,用户可以选择它们中的一个而不是接受所有license -->
    <licenses>
        <!--描述了项目的license,用于生成项目的web站点的license页面,其他一些报表和validation也会用到该元素。 -->
        <license>
            <!--license用于法律上的名称 -->
            <name>Apache 2</name>
            <!--官方的license正文页面的URL -->
            <url>http://a.b.com/nanxs/LICENSE-1.0.txt</url>
            <!--项目分发的主要方式: repo,可以从Maven库下载 manual, 用户必须手动下载和安装依赖 -->
            <distribution>repo</distribution>
            <!--关于license的补充信息 -->
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>
 
    <!--SCM(Source Control Management)标签允许你配置你的代码库,供Maven web站点和其它插件使用。 -->
    <scm>
        <!--SCM的URL,该URL描述了版本库和如何连接到版本库。该连接只读 -->
        <connection>scm:svn:http://a.b.com/nanxs</connection>
        <!--给开发者使用的,类似connection元素。即该连接不仅仅只读 -->
        <developerConnection>scm:svn:http://a.b.com/nanxs</developerConnection>
        <!--当前代码的标签,在开发阶段默认为HEAD -->
        <tag />
        <!--指向项目的可浏览SCM库(例如ViewVC或者Fisheye)的URL。 -->
        <url>http://a.b.com/nanxs</url>
    </scm>
 
    <!--描述项目所属组织的各种属性。Maven产生的文档用 -->
    <organization>
        <!--组织的全名 -->
        <name>demo</name>
        <!--组织主页的URL -->
        <url>http://a.b.com/nanxs</url>
    </organization>

13. Other configurations

    <!--描述了这个项目构建环境中的前提条件。 -->
    <prerequisites>
        <!--构建该项目或使用该插件所需要的Maven的最低版本 -->
        <maven />
    </prerequisites>
 
    <!--模块(有时称作子项目) 被构建成项目的一部分。列出的每个模块元素是指向该模块的目录的相对路径 -->
    <modules />
 
    <!--以值替代名称,Properties可以在整个POM中使用,也可以作为触发条件(见settings.xml中activation元素的说明) -->
    <!-格式是<name>value</name>。 -->
    <properties />
 
    <!--不推荐使用,现在Maven忽略该元素. -->
    <reports></reports>

Guess you like

Origin blog.csdn.net/qq_44696532/article/details/134176177