Maven setting. xml configuration file details, mavensetting. xml

Source: Internet
Author: User

Maven setting. xml configuration file details, mavensetting. xml

The Configuration File settings. xml of maven exists in two places:

1. Installation: $ {M2_HOME}/conf/settings. xml

2. user directory: $ {user. home}/. m2/settings. xml

The former is also called global configuration and takes effect for all users of the operating system. The latter is called user configuration and takes effect only for users of the current operating system. If both exist, their content will be merged, and the settings. xml in the user range will overwrite the global settings. xml.

After Maven is installed, settings. xml is not automatically generated in the user directory, and only the global configuration file is generated. To create a user-defined settings. xml file, copy the settings file in the installation path to the $ {user. home}/. m2/directory /. Maven's default settings. xml is a template that contains comments and examples. You can modify it quickly to meet your requirements.

Once the global configuration is changed, all users will be affected. If maven is upgraded, all configurations will be cleared. Therefore, copy and back up $ {M2_HOME}/conf/settings in advance. xml file. Generally, global settings are not recommended. xml.

Settings. xml

Statement Specification

<?xml version="1.0" encoding="UTF-8"?><settings 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/settings-1.0.0.xsd"> 

LocalRepository

<! -- Path of the local repository. The default value is $ {user. home}/. m2/repository. --> <LocalRepository> usr/local/maven </localRepository>

InteractiveMode

<! -- Does Maven need to interact with users to obtain input. If Maven needs to interact with users to obtain the input, set it to true. Otherwise, set it to false. The default value is true. --> <InteractiveMode> true </interactiveMode>

UsePluginRegistry

<! -- Does Maven need to use plugin-registry.xml files to manage plug-in versions. Set it to true if you want Maven to manage the plug-in version with the file $ {user. home}/. m2/plugin-registry.xml. The default value is false. --> <UsePluginRegistry> false </usePluginRegistry>

Offline

<! -- Indicates whether Maven needs to run in offline mode. If the build system needs to run in offline mode, the value is true. The default value is false. This configuration is useful when the build server cannot connect to a remote repository due to network settings or security factors. --> <Offline> false </offline>

PluginGroups

<! -- When the Organization Id (groupId) of the plug-in is not explicitly provided, you can search for the list of organization IDS (groupId) of the plug-in. This element contains a list of pluginGroup elements. Each child element contains a group Id (groupId ). When we use a plug-in without providing the Organization Id (groupId) in command behavior, Maven will use this list. By default, the list contains org. apache. maven. plugins and org. codehaus. mojo --> <pluginGroups> <! -- GroupId of the plugin organization --> <pluginGroup> org. codehaus. mojo </pluginGroup> </pluginGroups>

Proxies

<! -- Used to configure different proxies. Multi-proxy profiles can be used to cope with the notebook or mobile device's working environment: You can easily change the entire proxy configuration by setting the profile id. --> <Proxies> <! -- The proxy element contains the information required to configure the proxy --> <proxy> <! -- The unique identifier of the proxy, used to distinguish different proxy elements. --> <Id> myproxy </id> <! -- Whether the proxy is activated. If the value is true, the proxy is activated. When we declare a group of proxies, and at some point we only need to activate one proxy, this element can be used. --> <Active> true </active> <! -- Proxy protocol. Protocol: // host name: Port, separated into discrete elements for easy configuration. --> <Protocol> http </protocol> <! -- Proxy host name. Protocol: // host name: Port, separated into discrete elements for easy configuration. --> <Host> proxy.somewhere.com 

Servers

<! -- Configure some server settings. Some settings, such as security certificates, should not be distributed together with pom. xml. This type of information should exist in the settings. xml file on the build server. --> <Servers> <! -- The server element contains the information required to configure the server --> <server> <! -- This is the server id (not the user login id), which matches the id of the repository element in distributionManagement. --> <Id> server001 </id> <! -- Authentication username. The authentication username and password indicate the login name and password required for server authentication. --> <Username> my_login </username> <! -- Authentication password. The authentication username and password indicate the login name and password required for server authentication. The password encryption function has been added to 2.1.0 +. For more information, 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 password specify the path of a private key (default: $ {user. home }/. ssh/id_dsa) and a secret language if needed. Passphrase and password elements may be extracted externally in the future, but they must be declared in plain text in the settings. xml file. --> <PrivateKey >$ {usr. home}/. ssh/id_dsa </privateKey> <! -- The private key used for authentication. --> <Passphrase> some_passphrase </passphrase> <! -- Permission for creating a file. If a repository file or directory is created during deployment, you can use permission ). The valid values of these two elements are a three-digit number, which corresponds to the unix file system permissions, such as 664, or 775. --> <FilePermissions> 664 </filePermissions> <! -- Permission for Directory Creation. --> <DirectoryPermissions> 775 </directoryPermissions> </server> </servers>

Mirrors

<! -- Download the image list configured for the repository list. For advanced settings, see the image settings page --> <mirrors> <! -- Download the image from the specified repository. --> <Mirror> <! -- The unique identifier of the image. Id is used to differentiate different mirror elements. --> <Id> planetmirror.com </id> <! -- Image name --> <name> PlanetMirror Australia </name> <! -- The URL of the image. The build system gives priority to this URL instead of the default server URL. --> <Url> http://downloads.planetmirror.com/pub/maven2 </url> <! -- Id of the server to be mirrored. For example, if we want to set up an image for the Maven central repository (http://repo.maven.apache.org/maven2/), we need to set this element to central. This must be exactly the same as the id central of the central repository. --> <Mirrof> central </mirrorOf> </mirror> </mirrors>

Profiles

<! -- Adjust the configuration list based on environment parameters. The profile element in settings. xml is the cropped version of the profile element in pom. xml. It contains the id, activation, repositories, pluginRepositories, and properties elements. The profile element only contains these five sub-elements because it only cares about building the system as a whole (this is the role location of the settings. xml file), rather than setting the project object model separately. If a profile in settings is activated, its value will overwrite any other profile defined in POM or profile. xml with the same id. --> <Profiles> <! -- Configuration of components adjusted according to environment parameters --> <profile> <! -- The unique identifier of the configuration. --> <Id> test </id>

Activation

<! -- Trigger the conditional logic of the profile automatically. Activation is the key to enabling the profile. Like the profile in POM, the power of the profile is that it can automatically use certain values in certain environments; these environments are specified through the activation element. The activation element is not the only way to activate the profile. The activeProfile element in the settings. xml file can contain the profile id. Profile can also be explicitly activated (for example,-P test) by using the-P tag and comma-separated list in the command line ). --> <Activation> <! -- Whether the profile is activated by default. --> <activeByDefault> false </activeByDefault> <! -- When the matched jdk is detected, the profile is activated. For example, 1.4 activates JDK1.4, 1.4.0 _ 2, and! 1.4 activate all versions of JDK not starting with 1.4. --> <Jdk> 1.5 </jdk> <! -- When the matching operating system property is detected, the profile is activated. OS elements can define operating system-related attributes. --> <OS> <! -- Name of the operating system that activates the profile --> <name> Windows XP </name> <! -- Activates the operating system family of the profile (for example, 'windows') --> <family> windows </family> <! -- Activate the operating system architecture of the profile --> <arch> x86 </arch> <! -- Activate the operating system version of the profile --> <version> 5.1.2600 </version> </OS> <! -- If Maven detects an attribute (its value can be referenced through $ {name} in POM) and it has the corresponding name = value, the Profile will be activated. If the value field is empty, the profile is activated if the attribute name field exists. Otherwise, the attribute value field is matched in case-sensitive mode --> <property> <! -- Activate the name of the profile attribute --> <name> mavenVersion </name> <! -- Activate the attribute value of profile --> <value> 2.0.3 </value> </property> <! -- Provide a file name to activate the profile by checking whether the file exists or does not exist. Missing checks whether the file exists. If the file does not exist, the profile is activated. On the other hand, exists checks whether the file exists and activates the profile if it exists. --> <File> <! -- If the specified file exists, the profile is activated. --> <Exists >$ {basedir}/file2.properties </exists> <! -- If the specified file does not exist, the profile is activated. --> <Missing >$ {basedir}/file1.properties </missing> </file> </activation>

Properties

<! -- List of extended attributes corresponding to the profile. Maven attributes are the same as those in Ant and can be used to store some values. These values can be marked with $ {X} anywhere in POM. Here, X refers to the attribute name. Attributes can be accessed in the settings. xml file in five different forms. 1. env. X: prefix "env." Before a variable, a shell environment variable is returned. For example, "env. PATH" indicates the $ path environment variable (% PATH % on Windows ). 2. project. x: refers to the element value in POM. For example, <project> <version> 1.0 </version> </project> obtains the version value through $ {project. version. 3. settings. x: the value of the corresponding element in settings. xml. For example, <settings> <offline> false </offline> </settings> gets the offline value through $ {settings. offline. 4. Java System Properties: All attributes that can be accessed through java. lang. System. getProperties () can be accessed in POM in this form, for example, $ {java. home }. 5. x: In the <properties/> element or in an external file, it is used in the form of $ {someVar. --> <Properties> <user. install >$ {user. home}/our-project </user. install> </properties>

Note: If this profile is activated, you can use $ {user. install} in POM }.

Repositories

<! -- Remote repository list, which is a set of remote projects used by Maven to populate the local repository of the system. --> <Repositories> <! -- Contains information that needs to be connected to the remote warehouse --> <repository> <! -- Unique id of the remote warehouse --> <id> codehausSnapshots </id> <! -- Remote repository name --> <name> Codehaus Snapshots </name> <! -- How to download released versions in the remote repository --> <releases> <! -- True or false indicates whether the repository is enabled to download a certain type of component (release version, snapshot version. --> <Enabled> false </enabled> <! -- This element specifies the update frequency. Maven compares the timestamp of the local POM and remote POM. The options here are: always (always), daily (default, daily), interval: X (here, X is the time interval in minutes), or never (never ). --> <UpdatePolicy> always </updatePolicy> <! -- How to do this when the Maven verification component fails to verify the file-ignore (ignore), fail (failure), or warn (warning ). --> <ChecksumPolicy> warn </checksumPolicy> </releases> <! -- How to download the snapshot version in the remote repository. With the releases and snapshots configurations, POM can adopt different policies for each type of component in each separate repository. For example, someone may decide to enable snapshot Version Download only for development purposes. See the repositories/repository/releases element --> <snapshots> <enabled/> <updatePolicy/> <checksumPolicy/> </snapshots> <! -- Remote repository URL, in the form of protocol: // hostname/path --> <url> http://snapshots.maven.codehaus.org/maven2 </url> <! -- The repository layout type used to locate and sort components-default or legacy ). Maven 2 provides a default layout for its repository; however, Maven 1.x has a different layout. We can use this element to specify whether the layout is default or legacy ). --> <Layout> default </layout> </repository> </repositories> <! -- The remote repository list of the plugin is found. Warehouses are the home of two main components. The first component is used as the dependency of other components. This is the majority of Component Types stored in the central repository. Another component type is plug-in. 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 Maven remote address that can be used to find the new plug-in. --> <PluginRepositories> <! -- Contains information that needs to be connected to the remote plug-in repository. see the description of the profiles/profile/repositories/repository element --> <pluginRepository> <releases> <enabled/> <updatePolicy/> <checksumPolicy/> </releases> <snapshots> <enabled /> <updatePolicy/> <checksumPolicy/> </snapshots> <id/> <name/> <url/> <layout/> </pluginRepository> </pluginRepositories> </ profile> </profiles>

ActiveProfiles

<! -- Manually activate the list of profiles and define activeProfile according to the order in which the profile is applied. This element contains a group of activeProfile elements, and each activeProfile contains a profile id. Any profile id defined in activeProfile will be activated regardless of the environment settings. If no matching profile exists, nothing will happen. For example, if env-test is an activeProfile, the profile of the corresponding id in pom. xml (or profile. xml) is activated. If such a profile cannot be found during running, Maven runs as usual. --> <ActiveProfiles> <! --> <ActiveProfile> env-test </activeProfile> </activeProfiles> </settings>

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.