What's the use of settings.xml in Maven? And the role of various labels

What's the use of settings.xml?

If you have used the Maven plug-in in Eclipse, you must have this experience: configure the path to the settings.xml file.

What does the settings.xml file do? Why configure it?
As you can see from the file name of settings.xml, it is the configuration file used to set maven parameters. Also, settings.xml is the global configuration file for maven. The pom.xml file is the local configuration of the project.
Settings.xml contains configurations such as local warehouse location, remote warehouse server modification (such as Alibaba cloud remote warehouse), authentication information, etc. (for example, if a remote warehouse needs a user name and password, it also needs to be configured in this setting.xml).

Configure Alibaba cloud remote warehouse in setting.xml:

       <!-- Alibaba cloud warehouse -->
            <name>aliyun maven</name>
        <!-- Central warehouse 1 -->
            <name>Human Readable Name for this Mirror.</name>
        <!-- Central warehouse 2 -->
            <name>Human Readable Name for this Mirror.</name>


settings.xml file location

The settings.xml file generally exists in two places:
Global configuration: ${M2_HOME}/conf/settings.xml
User configuration: user.home/.m2/settings.xmlnote: user configuration takes precedence over global configuration. User. Home /. M2 / settings.xmlnote: user configuration takes precedence over global configuration. {user. Home} and all other system properties can only be used on version 3.0 +. Note the difference between using variables in windows and Linux.

Configure priority

eclipse needs to pay attention to the Maven project: local configuration takes precedence over global configuration.
Configuration priority from high to low: pom.xml > User Settings > global settings
If these files exist at the same time, their contents will be merged when the configuration is applied. If there are duplicate configurations, the configuration with higher priority will overwrite the one with lower priority.

settings.xml element details

Top level element overview

The top-level elements in settings.xml are listed below

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"


Role: this value indicates the path to build the local warehouse of the system.
The default value is ~ /. m2/repository.



Function: indicates whether maven needs to interact with users to get input.
Set to true if maven needs to interact with the user to get input, otherwise false. The default is true.



Function: whether maven needs to use plugin-registry.xml file to manage plug-in version.
Set to true if you want maven to use the file ~ /. m2/plugin-registry.xml to manage the plug-in version. The default is false.



Function: indicates whether maven needs to run in offline mode.
true if the build system needs to run in offline mode, and false by default.
This configuration is very useful when the construction server cannot connect to the remote warehouse due to network settings or security factors.



Role: when the plug-in's organization ID (groupId) is not explicitly provided, it is used to search the list of plug-in's organization ID (groupId).
This element contains a list of pluginGroup elements, each of which contains an organization Id (groupId).
When we use a plug-in and do not provide an organization Id (groupId) in the command line, Maven uses the list. By default, the list includes org.apache.maven.plugins and org.codehaus.mojo.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <!--plugin Organization Id(groupId) -->


Role: in general, the download and deployment of the warehouse are defined in the repositories and distribution management elements in the pom.xml file. However, information such as user name and password (some warehouse access requires security authentication) should not be configured in pom.xml file, which can be configured in settings.xml.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <!--Configure some settings of the server. Some settings, such as security certificates, should not match pom.xml Distributed together. This type of information should exist on the build server settings.xml In the document. -->
    <!--The server element contains the information needed to configure the server -->
      <!--This is server Of id(Note that it's not the user's login id),The id And distributionManagement in repository Elemental id Match. -->
      <!--Authentication user name. The authentication user name and password represent the login name and password required for server authentication. -->
      <!--Authentication password. The authentication user name and password represent the login name and password required for server authentication. Password encryption has been added to 2.1.0 +. Please visit password encryption page for details -->
      <!--The location of the private key used for authentication. Similar to the first two elements, the private key location and private key password specify the path of a private key (the default is ${user.home}/.ssh/id_dsa)And if necessary, a secret. future passphrase and password Elements may be extracted to the outside, but currently they must be settings.xml The file is declared in plain text. -->
      <!--The private key password used for authentication. -->
      <!--Permissions when the file is created. If a warehouse file or directory will be created during deployment, then permissions can be used( permission). The legal value of these two elements is a three digit number, which corresponds to unix File system permissions, such as 664, or 775. -->
      <!--Permissions when the directory is created. -->

Tags: Java Maven xml Apache Eclipse

Posted on Wed, 04 Mar 2020 00:17:35 -0800 by golfinggod