Brief introduction
The settings element in the Settings.xml file contains a number of child elements, and their defined values are used to configure the execution of MAVEN. The settings for this settings file are applied to many projects, so the settings here should not be bound to any particular project, and the contents of the settings should not be distributed to others. The value defined by this file includes the local warehouse address, the candidate remote warehouse repository server, and some authentication information. The settings.xml file can be located in two places:
maven installation directory: $M 2_home/conf/settings.xml
• User-specific settings file: ~/.m2/settings.xml
Here is an overview of the topmost elements under the settings element:
Overview of top-level elements in Settings.xml
<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/> <interactiveMode/> <usePluginRegistry/> <offline/> <pluginGroups/> <servers/> <mirrors/> <proxies/> <profiles/> <activeProfiles/> </settings>
Briefly introduce a few key configuration factors:
Localrepository: represents the location where the local library is saved, that is, the MAVEN2 main jar save location, by default in ${user.dir}/.m2/repository, and if additional settings are required, replace the other path.
offline: If you don't want to compile every time, look for the Remote Central Library, set to True. Of course, the prerequisite is that you have downloaded the necessary dependency pack.
Servers
The distributionmanagement element in the POM defines the development library. However, specific username and PWD cannot be used in Pom.xml, so this configuration saves server information
<servers> <server> <id>server001</id> <username>my_login</username> < Password>my_password</password> <privateKey>${usr.home}/.ssh/id_dsa</privateKey> < Passphrase>some_passphrase</passphrase> <filePermissions>664</filePermissions> < Directorypermissions>775</directorypermissions> <configuration></configuration> </server > </servers>
The Id:server ID, used to match the Distributionmanagement Library ID, is more important.
Username, Password: User name and password to log on to this server
Privatekey, passphrase: Set private key, and passphrase
Filepermissions, Directorypermissions: When a library file or directory is created, it needs to be accessed using permissions. Refer to UNIX file permissions, such as 664 and 775
Mirrors
Represents a mirrored library, specifying a mirror for the library, for adding additional libraries
<mirrors> <mirror> <id>planetmirror.com</id> <name>planetmirror australia</name > <url>http://downloads.planetmirror.com/pub/maven2</url> <mirrorof>central</mirrorof > </mirror> </mirrors>
Id,name: A unique flag used to distinguish mirrors
URL: A mirrored URL
MIRROROF: The service ID that this mirror points to
proxies
This setting is primarily used for library user configurations that do not have direct access to the center.
<proxies> <proxy> <id>myproxy</id> <active>true</active> <protocol>http </protocol>
ID: Flag for Agent
Active: Whether to activate the agent
Protocol, host, Port:protocol://host:port agent
Username, password: username and password
Nonproxyhosts: Host with no proxy required
Profiles
Similar to the profile elements in Pom.xml, mainly including the activation,repositories,pluginrepositories and properties elements in the beginning of contact, may be more confused, In fact, this is a relatively powerful function of maven2. Literally, is the disposition of personality. When profile is defined individually, it does not take effect and needs to be activated by satisfying the condition.
repositories and Pluginrepositories
Define other development libraries and plug-in development libraries. For a team, there must be a development library of its own. Can be defined by this configuration.
As the following configuration, a local development library is defined for release publishing.
<repositories> <repository> <id>repo-local</id> <name>internal Development Library </name> < Url>http://192.168.0.2:8082/repo-local</url> <releases> <enabled>true</enabled> < Updatepolicy>never</updatepolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <layout>default</layout> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>repo-local </id> <name>internal Development Library </name> <url>http://192.168.0.2:8082/repo-local</url> < Releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> < checksumpolicy>warn</checksumpolicy> </releases> <snapshots> <enabled>false</ enabled> </snapshots> <layout>default</layout> </pluginRepository> </ Pluginrepositories>
Releases, snapshots: Release or snapshot for each product version (note: The difference between releases and snapshot, release is generally a more stable version, and snapshot is basically unstable, just as a snapshot)
Properties
MAVEN's properties are used as placeholder values, such as Ant's Properties.
Includes the following 5 types of values:
Env. X, returns the current environment variable project.x: Returns the element value defined in the POM, such as project.version settings.x: Returns the element Java defined in Settings.xml System Properties: All values returned by Java.lang.System.getProperties () x: Value set by the user himself
activation
Used to activate this profile
<activation> <activeByDefault>false</activeByDefault> <jdk>1.5</jdk> <os> < Name>windows xp</name> <family>Windows</family> <arch>x86</arch> <version> 5.1.2600</version> </os> <property> <name>mavenVersion</name> <value>2.0.3< /value> </property> <file> <exists>${basedir}/file2.properties</exists> <missing> ${basedir}/file1.properties</missing> </file> </activation>
JDK: If the specified JDK version is matched, it will activate
OS: Operating system
Property: If Maven can detect the corresponding properties
File: Used to determine whether or not files exist
In addition to using activation to activate profile, the same can be activated by activeprofiles
Active Profiles
Represents the active profile, specified by the profile ID.
<activeProfiles> <activeProfile>env-test</activeProfile> specified profile ID </activeprofiles >