1. Summary
1.1 settings. What's the use of XML
settings. What does an XML file do and why configure it?
From settings As can be seen from the file name of XML, it is a configuration file used to set maven parameters. And, settings XML is the global configuration file of maven. POM The XML file is the local configuration of the project.
Settings.xml contains configurations such as local storage location, modifying remote storage server, authentication information, etc.
1.2 configuration priority
It should be noted that 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 applying the configuration. If there are duplicate configurations, the configuration with high priority will overwrite the configuration with low priority.
2. Element details
2.1 list of top-level elements
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository/> <interactiveMode/> <usePluginRegistry/> <offline/> <pluginGroups/> <servers/> <mirrors/> <proxies/> <profiles/> <activeProfiles/> </settings>
2.2 LocalRepository
Function: this value indicates the path to build the local warehouse of the system.
Its default value: ~ / m2/repository.
<localRepository>${user.home}/.m2/repository</localRepository>
2.3 InteractiveMode
Function: indicates whether maven needs to interact with users to obtain input.
If maven needs to interact with the user to get input, it should be set to true, otherwise it should be false. The default is true.
<interactiveMode>true</interactiveMode>
2.4 UsePluginRegistry
Function: whether maven needs to use plugin registry XML file to manage the plug-in version.
If necessary, let maven use the file ~ / m2/plugin-registry.xml to manage the plug-in version, set to true. The default is false.
<usePluginRegistry>false</usePluginRegistry>
2.5 Offline
Function: indicates whether maven needs to run in offline mode.
If the build system needs to run in offline mode, it is true and the default is false.
This configuration is useful when the build server cannot connect to the remote warehouse due to network settings or security factors.
<offline>false</offline>
2.6 PluginGroups
Function: when the organization ID (groupId) of the plug-in is not explicitly provided, it is used to search the list of plug-in organization ID (groupId).
This element contains a list of pluginGroup elements, and each child element contains an organization Id (groupId).
Maven uses this list when we use a plug-in and do not provide the organization Id (groupId) in the command line. By default, the list contains org. Org apache. maven. Plugins and org codehaus. mojo.
<pluginGroups> <!--plugin Organization of Id(groupId) --> <pluginGroup>org.codehaus.mojo</pluginGroup> </pluginGroups>
2.7 Servers
Function: generally, the download and deployment of the warehouse is in POM Defined in the repositories and distributionManagement elements in the XML file. However, generally, information such as user name and password (some warehouse access requires security authentication) should not be in POM XML file, which can be configured in settings XML.
<!--Configure some server settings. Some settings, such as security certificates, should not be associated with pom.xml Distribute together. This type of information should exist on the build server settings.xml File. --> <servers> <!--The server element contains the information needed to configure the server --> <server> <!--This is server of id(Note that the user is not logged in id),Should id And distributionManagement in repository Elemental id Match. --> <id>server001</id> <!--Authentication user name. The authentication user name and authentication password represent the login name and password required for server authentication. --> <username>my_login</username> <!--Authentication password. The authentication user name and authentication password represent the login name and password required for server authentication. Password encryption has been added to 2.1.0 +. For details, please visit the password encryption page --> <password>my_password</password> <!--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 word. future passphrase and password Elements may be extracted externally, but for now they must be settings.xml The document is declared in plain text. --> <privateKey>${usr.home}/.ssh/id_dsa</privateKey> <!--The private key password used for authentication. --> <passphrase>some_passphrase</passphrase> <!--Permissions when the file is created. If a warehouse file or directory will be created during deployment, permissions can be used at this time( 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. --> <filePermissions>664</filePermissions> <!--Permissions when the directory is created. --> <directoryPermissions>775</directoryPermissions> </server> </servers>
2.8 Mirrors
Function: Download Image List configured for warehouse list.
<mirrors> <!-- Download Image of a given warehouse. --> <mirror> <!-- Unique identifier of the mirror. id Used to distinguish between different mirror Element. --> <id>planetmirror.com</id> <!-- Image name --> <name>PlanetMirror Australia</name> <!-- Of the mirror URL. Building the system will give priority to the use of this URL,Instead of using the default server URL. --> <url>http://downloads.planetmirror.com/pub/maven2</url> <!-- Of the mirrored server id. For example, if we want to set up a Maven Central warehouse( http://repo.maven.apache.org/maven2 /), you need to set this element to central. This must be exactly the same as the id central of the central warehouse. -- > <mirrorOf>central</mirrorOf> </mirror> </mirrors>
2.9 Proxies
Function: used to configure different agents.
<proxies> <!--The agent element contains the information needed to configure the agent --> <proxy> <!--The unique definer of the proxy, which is used to distinguish different proxy elements. --> <id>myproxy</id> <!--Whether the agent is the active one. true Then activate the agent. This element is useful when we declare a set of agents and only need to activate one agent at a time. --> <active>true</active> <!--Agency agreement. agreement://Hostname: port, separated into discrete elements for easy configuration. -- > <protocol>http</protocol> <!--The host name of the agent. agreement://Hostname: port, separated into discrete elements for easy configuration. -- > <host>proxy.somewhere.com</host> <!--The port of the agent. agreement://Hostname: port, separated into discrete elements for easy configuration. -- > <port>8080</port> <!--The user name, user name and password of the agent represent the login name and password authenticated by the proxy server. --> <username>proxyuser</username> <!--The password of the proxy. The user name and password represent the login name and password authenticated by the proxy server. --> <password>somepassword</password> <!--List of host names that should not be proxied. The separator of the list is specified by the proxy server; The vertical bar separator is used in the example, and comma separation is also common. --> <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts> </proxy> </proxies>
2.10 Profiles
Function: adjust the list of build configurations according to environment parameters.
settings. The profile element in XML is POM A cropped version of the profile element in XML.
It contains the id, activation, repositories, pluginRepositories, and properties elements. The profile element here only contains these five sub elements because it 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 setting The profile in XML is activated, and its value overrides any other defined in pom.xml A profile with the same id in the XML.
<profiles> <profile> <!-- profile Unique identification of --> <id>test</id> <!-- Automatic trigger profile Conditional logic --> <activation /> <!-- Extended attribute list --> <properties /> <!-- Remote warehouse list --> <repositories /> <!-- List of plug-in warehouses --> <pluginRepositories /> </profile> </profiles>
2.11 Activation
Function: automatically trigger the conditional logic of the profile.
Such as POM Like the profile in XML, the function of profile is that it can automatically use some specific values in some specific environments; These environments are specified through the activation element.
The activation element is not the only way to activate a profile. settings. The activeProfile element in the XML file can contain the id of the profile. Profile can also be explicitly activated by using - P tag and comma separated list on the command line (for example, - P test).
<activation> <!--profile Default active ID --> <activeByDefault>false</activeByDefault> <!--When matched jdk Detected, profile Activated. For example, 1.4 activation JDK1.4,1.4.0_2,and!1.4 Activate all versions not in 1.4 initial JDK. --> <jdk>1.5</jdk> <!--When a matching operating system attribute is detected, profile Activated. os Element can define some operating system related attributes. --> <os> <!--activation profile The name of the operating system --> <name>Windows XP</name> <!--activation profile Family of operating systems(as 'windows') --> <family>Windows</family> <!--activation profile Operating system architecture --> <arch>x86</arch> <!--activation profile Operating system version of --> <version>5.1.2600</version> </os> <!--If Maven A property has been detected whose value can be POM Passed in ${name}Reference), which has the corresponding name = 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 --> <property> <!--activation profile The name of the property --> <name>mavenVersion</name> <!--activation profile The value of the property --> <value>2.0.3</value> </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. --> <file> <!--Activate if the specified file exists profile. --> <exists>${basedir}/file2.properties</exists> <!--Activate if the specified file does not exist profile. --> <missing>${basedir}/file1.properties</missing> </file> </activation>
Note: in the POM of maven project Execute the MVN help: active profiles command in the directory where XML is located to check whether the profile of the central warehouse is effective in the project.
2.12 properties
Function: the extended attribute list of the corresponding profile.
The maven attribute, like the attribute in ant, can be used to store some values. These values can be found in POM Use the tag ${X} anywhere in XML, where X refers to the name of the attribute. There are five different forms of attributes, all of which can be found in settings XML file.
<!-- 1. env.X: Add before a variable"env."A prefix is returned shell Environment variables. for example,"env.PATH"Refers to $path Environment variables (in Windows It is%PATH%). 2. project.x: Refers to POM The corresponding element value in. for example: <project><version>1.0</version></project>adopt ${project.version}get version Value of. 3. settings.x: Refers to settings.xml The value of the corresponding element in the. For example:<settings><offline>false</offline></settings>adopt ${settings.offline}get offline Value of. 4. Java System Properties: All available java.lang.System.getProperties()The accessed properties can be POM Use this form of access in, for example ${java.home}. 5. x: stay<properties/>Element, or in an external file, to ${someVar}Use in the form of. --> <properties> <user.install>${user.home}/our-project</user.install> </properties>
Note: if the profile is activated, it can be in POM Use ${user.install} in XML.
2.13 Repositories
Function: remote warehouse list, which is used by maven to fill in a group of remote warehouses used to build the local warehouse of the system.
<repositories> <!--Contains information that needs to be connected to the remote warehouse --> <repository> <!--Unique identification of remote warehouse --> <id>codehausSnapshots</id> <!--Remote warehouse name --> <name>Codehaus Snapshots</name> <!--How to handle the download of release version in remote warehouse --> <releases> <!--true perhaps false Indicates whether the warehouse is enabled for downloading certain types of components (release version, snapshot version). --> <enabled>false</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>always</updatePolicy> <!--When Maven What to do when verifying the component verification file fails-ignore(Ignore), fail(Failure), or warn(Warning). --> <checksumPolicy>warn</checksumPolicy> </releases> <!--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 may decide to turn on support for snapshot version download only for development purposes. See repositories/repository/releases element --> <snapshots> <enabled /> <updatePolicy /> <checksumPolicy /> </snapshots> <!--Remote warehouse URL,Press protocol://hostname/path form -- > <url>http://snapshots.maven.codehaus.org/maven2</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, Maven 1.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> </repository> </repositories>
2.14 pluginRepositories
Role: discover the list of remote warehouses of plug-ins.
Similar to repository, repository is the repository for managing jar packages, and pluginRepositories is the repository for managing plug-ins.
The Maven plug-in is a special type of component. For this reason, the plug-in repository is independent of other repositories. The structure of the pluginRepositories element is similar to that of the repositories element. Each pluginRepository element specifies a remote address that Maven can use to find new plug-ins.
<pluginRepositories> <!-- Contains information about the need to connect to the remote plug-in repository.See profiles/profile/repositories/repository Description of the element --> <pluginRepository> <id> </id> <name> </name> <url> </url> <layout> </layout> <releases> <enabled> </enabled> <updatePolicy> </updatePolicy> <checksumPolicy> </checksumPolicy> </releases> <snapshots> <enabled> </enabled> <updatePolicy> </updatePolicy> <checksumPolicy> </checksumPolicy> </snapshots> </pluginRepository> </pluginRepositories>
2.15 ActiveProfiles
Function: manually activate the list of profiles and define active profiles in the order in which profiles are applied.
This element contains a set of active profile elements, and each active profile contains a profile id. Any profile id defined in activeProfile will be activated regardless of the environment settings. If there is no matching profile, nothing will happen.
For example, if env test is an active profile, it is in POM The profile of the corresponding id in the XML (or profile.xml) will be activated. If such a profile cannot be found during operation, Maven will run as usual.
<activeProfiles> <!-- To activate profile id --> <activeProfile>env-test</activeProfile> </activeProfiles>