Maven's POM XML configuration file details

[detailed explanation of Maven's pom.xml configuration file]

setting.xml is mainly used to configure a series of general attributes such as maven's running environment. It is a global level configuration file; POM XML mainly describes the maven coordinates of the project, dependencies, rules that developers need to follow, defect management system, organization and licenses, and all other project related factors. It is a project level configuration file.

Basic configuration

A typical POM The XML file configuration is as follows:

<project xmlns="" xmlns:xsi=""

    <!-- Model version. maven2.0 It must be written like this. Now it is maven2 Only supported version -->

    <!-- The unique flag of the company or organization, and the path generated during configuration is also generated from it, such as com.demo.luchen,maven The project will be marked as jar Package local path:/com/demo/luchen -->

    <!-- Unique of the project ID,One groupId There may be several projects below, which rely on artifactId To distinguish -->

    <!-- Current version number of the project -->

    <!-- Packaging mechanism, such as pom,jar, maven-plugin, ejb, war, ear, rar, par,Default to jar -->

    <!-- Some ancillary components that help define component output,The auxiliary component corresponds to the main component, which sometimes needs to be added classifier To uniquely determine that the component cannot directly define the project classifer,Because accessory components are not directly generated by default, but are generated with the help of additional plug-ins -->

    <!-- Define dependencies of this project -->

        <!-- each dependency All correspond to this one jar package -->

            <!--Normally, maven Yes groupId,artifactId,version These three element values (commonly known as coordinates) are used to retrieve the component, and then introduce it into your project. If others want to reference the project you are developing (provided that it has been developed and published to the remote warehouse),-->
            <!--You need to be in his office pom Create a new one in the file dependency Node, which will groupId,artifactId,version write in, maven I'll upload you jar Download the package to his local -->

            <!-- maven It is considered that the external dependence of the program will change with the stage and application scenario of the program, so maven Dependencies in have scope(scope)Limitations. -->
            <!--scope Include the following values: compile(Compilation scope) provided(Scope provided) runtime(Runtime range) test(Test scope) system((system scope) -->

            <!-- Setting refers to whether dependency is optional. The default value is false,That is, all subprojects inherit by default:by true,The import required for the sub item, and dependencyManagement Dependencies defined in are similar  -->

            <!-- Mask dependencies. Such as those used in the project libA 1 dependent on a library.0 Version, libB 2 dependent on a library.0 Version 2. Now I want to use it uniformly.0 Version 1 should be blocked.0 Version dependency -->



    <!-- by pom Define some constants in pom Other parts of the can be directly referenced and used as follows: ${file.encoding} -->


The classifier element is used to help define some subsidiary components of the component output. The auxiliary component corresponds to the main component. For example, the main component is kimi-app-2.0 0. Jar, which may also be generated by using some plug-ins, such as kimi-app-2.0 0-javadoc. Jar (Java document) and kimi-app-2.0.0-sources.jar (Java source code). At this time, Javadoc and sources are the classifiers of these two auxiliary components, so that the auxiliary components have their own unique coordinates.

The purpose of classifier is to:

  1. When Maven downloads the Javadoc / sources jar package, you need to use the classifier to indicate which accessory component to download

  2. When introducing dependencies, sometimes a component cannot be uniquely determined only by groupId, artifactId and version, and the classifier needs to be used to further clarify the goal. For example, JSON lib sometimes provides multiple jar packages together with one version, which is in jdk1 5 environment is a set, in jdk1 3 environment is a set. When quoting it, you should indicate the JDK version, otherwise maven doesn't know which jar package you need:


Build configuration

    <!-- The file name of the generated component. The default value is ${artifactId}-${version}.  -->  
    <!-- The directory where all files generated by the build are stored,Default to ${basedir}/target,That is, under the root directory of the project target -->  
    <!--When the project has no specified objectives( Maven2 It's called stage( phase))The default value when, -->  
    <!--Must be the same as the parameters on the command line, for example jar:jar,Or with a stage( phase)Same example install,compile etc. -->  
    <!--When filtering List of filter properties files used when the switch is on. -->  
    <!--In the project configuration information, such as ${spring.version}Placeholders such as are replaced by actual values in the properties file -->  
    <!--List of all resource paths related to the project, such as configuration files and property files related to the project. These resources are included in the final packaging file. -->  
            <!--Describes the target path of the resource. The path is relative target/classes Directory (e.g ${}).  -->  
            <!--For example, if you want resources in a specific package(org.apache.maven.messages),You must set the element to org/apache/maven/messages.  -->  
            <!--However, if you just want to put resources into the source directory structure, you don't need this configuration. -->  
            <!--Whether to use parameter value instead of parameter name. Parameter values are taken from properties Element or attribute configured in the file filters Element. -->  
            <!--Describes the directory where resources are stored. The path is relative POM route -->  
            <!--List of modes included -->  
            <!--List of excluded modes if<include>And<exclude>There is a conflict in the delimited scope to<exclude>Subject to -->  
    <!--All resource paths related to unit testing, configuration methods and resources similar -->  
            <targetPath />  
            <filtering />  
            <directory />  
            <includes />  
            <excludes />  
    <!--Project source directory. When building a project, the construction system will compile the source code in the directory. The path is relative to pom.xml The relative path of the. -->  
    <!--The project script source directory is different from the source directory, <!-- In most cases, the contents of this directory will be copied to the output directory(Because scripts are interpreted, not compiled).  -->  
    <!--The source code directory used for project unit testing. When testing the project, the build system will compile the source code in the directory. The path is relative to pom.xml The relative path of the. -->  
    <!--Compiled application class Directory where files are stored. -->  
    <!--Compiled tests class Directory where files are stored. -->  
    <!--A series of build extensions for the project,They are a series build The products to be used in the process will be included in running bulid's classpath Inside. -->  
    <!--They can turn it on extensions,It can also be activated by providing conditions plugins.  -->  
    <!--In short, extensions Yes build Process activated product -->  
        <!--For example, usually, the program is deployed online after development Linux Server, may need to go through packaging -->  
        <!--Transfer package files to the server SSH Connect to the server, knock the command to start the program and a series of cumbersome steps. -->  
        <!--In fact, these steps can be passed Maven A plug-in for wagon-maven-plugin To automate -->  
        <!--The following extensions wagon-ssh Used to pass SSH To connect to the remote server, -->  
        <!--Similarly, there is support ftp Mode wagon-ftp plug-in unit -->  
    <!--List of plug-ins used. -->  
            <!--The configuration of a set of goals is performed during the build lifecycle. Each target may have a different configuration. -->  
                    <!--The identifier of the execution target, which is used to identify the target in the construction process or match the execution target to be merged in the inheritance process -->  
                    <!--The construction lifecycle phase of the target is bound. If omitted, the target will be bound to the default phase configured in the source data -->  
                    <!--Configured execution target -->  
                    <!--Is the configuration propagated to the child POM -->  
            <!--As DOM Object configuration,Configuration items vary from plug-in to plug-in -->  
            <!--Download from this plugin Maven Extensions (such as packaging and type processors), -->  
            <!--For performance reasons, this element is set to only when it really needs to be downloaded true.  -->  
            <!--Additional dependencies required for the project to introduce plug-ins -->  
            <!--Is any configuration propagated to subprojects -->  
    <!--It mainly defines the common element and extension element collection of plug-ins, similar to dependencyManagement, -->  
    <!--All subprojects inherited from this project can be used. The plug-in configuration item will not be resolved or bound to the lifecycle until it is referenced. -->  
    <!--Any local configuration of a given plug-in will override the configuration here -->  

The warehouse and setting in pom The warehouse function in XML is the same. The main difference is that the warehouse in pom is personalized. For example, the setting file in a large company is public, and all projects use one setting file, but each sub project will refer to different third-party libraries, so you need to set the warehouse address you need in pom.

Distribution configuration

<!--Project distribution information during implementation mvn deploy After indicates the location to publish. -->  
<!--With this information, you can deploy the website to a remote server or components to a remote warehouse. -->  
    <!--The information required to deploy the components generated by the project to the remote warehouse -->  
        <!--Is a unique version number assigned to the snapshot (consisting of timestamp and build serial number), or does it use the same version number every time -->  
        <!--See repositories/repository element -->  
        <id> repo-id </id>  
        <name> repo-name</name>  
        <url>file://${basedir}/target/deploy </url>  
        <layout />  
    <!--Where is the snapshot of the component deployed,If the element is not configured, it is deployed to by default repository Warehouse for element configuration -->  
        <uniqueVersion />  
        <id />  
        <name />  
        <url />  
        <layout />  
    <!--Information required to deploy the project's Web site -->  
        <!--Unique identifier of the deployment location that matches the site and settings.xml Configuration in file -->  
        <id> site-id </id>  
        <!--Name of the deployment location -->  
        <name> site-name</name>  
        <!--Deployment location URL,Press protocol://hostname/path form -- >  
        <url>scp:// </url>  
    <!--Of the project download page URL. If there is no such element, the user should refer to the home page. -->  
    <!--The reason for using this element is to help locate components that are not in the warehouse (due to license Restrictions). -->  
    <downloadUrl />  
    <!--If the component has a new groupID and artifact ID(The relocation information of the component is listed here. -->  
        <!--Component NEW group ID -->  
        <groupId />  
        <!--Component NEW artifact ID -->  
        <artifactId />  
        <!--The new version number of the component -->  
        <version />  
        <!--Additional information displayed to the user about the move, such as the reason. -->  
        <message />  
    <!--The status of the component in the remote warehouse is given. This element must not be set in a local project because it is automatically updated by the tool. -->  
    <!--Valid values are: none(Default), converted(Warehouse keeper from Maven 1 POM Switch over), -->  
    <!--partner(Directly from partner Maven 2 Warehouse synchronization), deployed(from Maven 2 Instance deployment), verified(Correct and final when verified). -->  
    <status />  

Warehouse configuration

<!--Discover a list of dependent and extended remote warehouses. -->  
    <!--Contains information that needs to be connected to the remote warehouse -->  
        <!--How to handle the download of release version in remote warehouse -->  
            <!--true perhaps false Indicates whether the warehouse is enabled for downloading certain types of components (release version, snapshot version). -->  
            <enabled />  
            <!--This element specifies how often updates occur. Maven Will compare local POM And remote POM The timestamp of the. -->  
            <!--The options here are: always(All the time), daily(Default, daily), -->  
            <!--interval: X(here X Is the time interval in minutes), or never(Never). -->  
            <updatePolicy />  
            <!--When Maven What to do when verifying the component verification file fails: -->  
            <!--ignore(Ignore), fail(Failed), or warn(Warning). -->  
            <checksumPolicy />  
        <!--How to handle the download of snapshot version in remote warehouse. Yes releases and snapshots These two sets of configurations, -->  
        <!--POM You can adopt different strategies for each type of component in each separate warehouse. -->  
        <!--For example, someone might decide to turn on support for snapshot version download only for development purposes -->  
            <enabled />  
            <updatePolicy />  
            <checksumPolicy />  
        <!--Unique identifier of the remote warehouse. Can be used to match in settings.xml Remote warehouse configured in file -->  
        <id> repo-id </id>  
        <!--Remote warehouse name -->  
        <name> repo-name</name>  
        <!--Remote warehouse URL,Press protocol://hostname/path form -- >  
        <url> </url>  
        <!--Warehouse layout type used to locate and sort components-Can be default(Default) or legacy(Legacy). -->  
        <!--Maven 2 Provides a default layout for its warehouse; -->  
        <!--However, Maven1.x There is a different layout. -->  
        <!--We can use this element to specify that the layout is default(Default) or legacy(Legacy). -->  
        <layout> default</layout>  
<!--Discover a list of remote repositories for plug-ins that are used to build and report -->  
    <!--Contains information about the need to connect to the remote plug-in repository.See repositories/repository element -->  
    <pluginRepository />  

Profile configuration

<!--Project build in column profile,If activated, the build process is modified -->  
    <!--Activate a build process based on environment parameters or command line parameters -->  
        <!--Automatic trigger profile Conditional logic. Activation yes profile Open the key. -->  
            <!--profile Default active ID -->  
            <!--activation There is a built-in java Version detection, if detected jdk The version is as expected, profile Activated. -->  
            <!--When a matching operating system attribute is detected, profile Activated. os Element can define some operating system related attributes. -->  
                <!--activation profile The name of the operating system -->  
                <name>Windows XP</name>  
                <!--activation profile Family of operating systems(as 'windows') -->  
                <!--activation profile Operating system architecture -->  
                <!--activation profile Operating system version of -->  
            <!--If Maven A property has been detected whose value can be POM Passed in ${name}Reference), which has the corresponding name and value, Profile Will be activated. -->  
            <!-- If the value field is empty, the existing attribute name field is activated profile,Otherwise, attribute value fields are matched case sensitive -->  
                <!--activation profile The name of the property -->  
                <!--activation profile The value of the property -->  
            <!--Provide a file name to activate by detecting the presence or absence of the file profile. missing Check whether the file exists, and activate if it does not exist profile.  -->  
            <!--on the other hand, exists The file is checked for existence and activated if it exists profile.  -->  
                <!--Activate if the specified file exists profile.  -->  
                <!--Activate if the specified file does not exist profile.  -->  
        <id />  
        <build />  
        <modules />  
        <repositories />  
        <pluginRepositories />  
        <dependencies />  
        <reporting />  
        <dependencyManagement />  
        <distributionManagement />  
        <properties />  

The profile configuration item is in setting XML, POM A cropped version of the profile element in XML, including id, activation, repositories, pluginRepositories, and properties elements. The profile element here only contains these five child elements because setting XML only cares about building the system as a whole (which is the role orientation of the settings.xml file), rather than individual project object model settings. If a profile in settings is activated, its value will overwrite any other profile with the same id defined in POM or profile.xml.

pom. The profile in XML can be regarded as POM XML, with POM XML has the same child elements and configuration methods. It contains optional activation (trigger of profile) and a series of changes. For example, the test process may point to different databases (relative to the final deployment) or different dependencies or different repositories, which are changed according to different jdks. Only one of them is valid to activate the profile. If the first condition is met, there will be no matching later.

Report configuration

<!--Describes the specification for generating reports using the report plug-in,Specific maven The plug-in can output corresponding customized and configuration reports. -->  
<!--When the user executes“ mvn site",These reports will run,You can see links to all reports in the page navigation bar. -->  
    <!--true,The web site does not include the default report. This includes reports in the project information menu. -->  
    <excludeDefaults />  
    <!--Where are all generated reports stored. The default value is ${}/site.  -->  
    <outputDirectory />  
    <!--Report plug-ins used and their configuration. -->  
            <groupId />  
            <artifactId />  
            <version />  
            <inherited />  
            <!--Multiple specifications for a set of reports. Each specification may have different configurations. -->  
            <!--A specification (report set) corresponds to an execution target. For example, there are 1, 2, 3, 4, 5, 6, 7, 8 and 9 reports. -->  
            <!--1,2,5 constitute A Report set, corresponding to an execution target. Composition of 2, 5 and 8 B Report set, corresponding to another execution target -->  
                <!--Represents a collection of reports and the configuration that generated the collection -->  
                    <!--Unique identifier of the report collection, POM Used in inheritance -->  
                    <!--The configuration of the report used when generating the report collection -->  
                    <configuration />  
                    <!--Is the configuration inherited to the child POMs -->  
                    <inherited />  
                    <!--Which reports are used in this collection -->  

Environment configuration

<!--Project problem management system(Bugzilla, Jira, Scarab,Or any problem management system you like)Name and URL,This example is jira -->  
    <!--Problem management system (e.g jira)Your name, -->  
    <system> jira </system>  
    <!--The problem management system used in the project URL -->  
<!--Project continuous integration information -->  
    <!--Name of the continuous integration system, e.g continuum -->  
    <system />  
    <!--The continuous integration system used in the project URL(If the continuous integration system has web Interface). -->  
    <url />  
    <!--Developers to be notified when the build is complete/User's configuration item. Include notifiee information and notification conditions (error, failure, success, warning) -->  
        <!--Configure a way to notify the user when the build is interrupted/developer -->  
            <!--Route of notification -->  
            <type />  
            <!--Notify when an error occurs -->  
            <sendOnError />  
            <!--Notify if build fails -->  
            <sendOnFailure />  
            <!--Notify when build is successful -->  
            <sendOnSuccess />  
            <!--Notify when a warning occurs -->  
            <sendOnWarning />  
            <!--Do not approve of using. Where is the notification sent -->  
            <address />  
            <!--Extended configuration item -->  
            <configuration />  

Project information configuration

<!--Name of the project, Maven Generated documents -->  
<name>banseon-maven </name>  
<!--Project home page URL, Maven Generated documents -->  
<url> </url>  
<!--Detailed description of the project, Maven The generated document is used. When this element can be used HTML Format description -->  
<!--(For example, CDATA The text in is ignored by the parser and can be included HTML Label), plain text description is not encouraged. -->  
<!-- If you need to modify the generated web For the index page of the site, you should modify your own index page file instead of adjusting the documents here. -->  
<description>A maven project to study maven. </description>  
<!--Describes the prerequisites in the project build environment. -->  
    <!--Required to build the project or use the plug-in Maven Minimum version of -->  
    <maven />  
<!--Project creation year, 4 digits. This value is required when generating copyright information. -->  
<inceptionYear />  
<!--Project related mailing list information -->  
    <!--This element describes all mailing lists related to the project. Automatically generated websites reference this information. -->  
        <!--The name of the message -->  
        <name> Demo </name>  
        <!--The address or link to which the mail is sent. If it is a mail address, when creating a document, mailto: The link is automatically created -->  
        <!--Subscribe to the email address or link. If it is an email address, when creating a document, mailto: The link is automatically created -->  
        <!--Unsubscribe from the mail address or link. If it is a mail address, when creating a document, mailto: The link is automatically created -->  
        <!--You can browse email information URL -->  
<!--Project developer list -->  
    <!--Information about a project developer -->  
        <!--SCM Unique identifier of the project developer in the -->  
        <id> HELLO WORLD </id>  
        <!--Full name of the project developer -->  
        <name> Programmer 1024 </name>  
        <!--Project developer's email -->  
        <!--Project developer's home page URL -->  
        <url />  
        <!--The role of the project developer in the project. The role element describes various roles -->  
            <role> Project Manager</role>  
            <role>Architect </role>  
        <!--Organization of project developer -->  
        <organization> demo</organization>  
        <!--Organization of the project developer URL -->  
        <organizationUrl> </organizationUrl>  
        <!--Project developer attributes, such as how to handle instant messages, etc -->  
            <dept> No </dept>  
        <!--The time zone of the project developer, -11 An integer in the range from to 12. -->  
        <timezone> +8 </timezone>  
<!--List of other contributors to the project -->  
    <!--Other contributors to the project. See developers/developer element -->  
        <name />  
        <email />  
        <url />  
        <organization />  
        <organizationUrl />  
        <roles />  
        <timezone />  
        <properties />  
<!--This element describes all of the project License List. You should list only for this item license List, do not list dependent items license List. -->  
<!--If more than one is listed license,Users can choose one of them instead of accepting all of them license.  -->  
    <!--Describes the of the project license,Used to build the project web Site license Page, some other reports and validation This element is also used. -->  
        <!--license Used as a legal name -->  
        <name> Apache 2 </name>  
        <!--Official license Text page URL -->  
        <url> </url>  
        <!--Main methods of project distribution: repo,Can from Maven Library Download manual, Users must manually download and install dependencies -->  
        <distribution> repo</distribution>  
        <!--about license Supplementary information for -->  
        <comments> Abusiness-friendly OSS license </comments>  
<!--SCM(Source Control Management)Tags allow you to configure your code base for Maven web Site and other plug-ins. -->  
    <!--SCM of URL,Should URL Describes the version library and how to connect to it. For details, please see SCMs Provided URL Format and list. The connection is read-only. -->  
    <!--For developers, similar connection Element. That is, the connection is not only read-only -->  
    <!--The label of the current code, which defaults to in the development phase HEAD -->  
    <tag />  
    <!--Browsable to the item SCM Library (e.g ViewVC perhaps Fisheye)of URL.  -->  
<!--Describes various attributes of the organization to which the project belongs. Maven Generated documents -->  
    <!--Full name of the organization -->  
    <name> Programmer 1024  </name>  
    <!--Organization home page URL -->  

Keywords: Java Maven xml

Added by celavi on Tue, 14 Dec 2021 15:13:15 +0200