译文:Documentation for settings.xml
The settings element in the settings.xml file contains elements used to define values which configure Maven execution in various ways, like thepom.xml, but should not be bundled to any specific project, or distributed to an audience. These include values such as the local repository location, alternate remote repository servers, and authentication information.
settings.xml文件中包含的元素用来定义以不同的方式运行Maven的配置,就像pom.xml文件,但是不予具体的项目进行捆绑不应捆绑到任何具体的项目。例如:其中的包含的值有本地仓库的位置,备用远程仓库服务器和身份验证信息等等。
There are two locations where a settings.xml file may live(settings.xml文件出现的两个位置):
The former settings.xml are also called global settings, the latter settings.xml are referred to as user settings. If both files exists, their contents gets merged, with the user-specific settings.xml being dominant.
前者是全局设置,后者被称为用户设置。如果两个文件都存在,他们的内容就会被合并,但是用户设置占据主导地位。简单来说就是:用户设置有的使用用户设置,没有的才去使用全局设置。
Tip: If you need to create user-specific settings from scratch, it’s easiest to copy the global settings from your Maven installation to your ${user.home}/.m2 directory. Maven’s default settings.xml is a template with comments and examples so you can quickly tweak it to match your needs.
技巧:如果你需要从零开始创建用户自定义设置,最容易的方式是从Maven安装目录下复制全局设置到你的${user.home}/.m2文件夹中。Maven提供的默认的settings.xml文件是包含了意见与实例的模板,因此你可以快速的调整到适合你的需求。
Here is an overview of the top elements under settings(下面是罗列出了所有的顶级元素):
The contents of the settings.xml can be interpolated using the following expressions(settings.xml中的内容可以使用下面的表达式):
Note that properties defined in profiles within the settings.xml cannot be used for interpolation.
注意:定义在配置文件内的settings.xml不能属性进行插值。
上面环境变量的使用例子:我们的java的环境变量的名称为:JAVA_HOME,我们可以使用${env.JAVA_HOME}来引用这个变量值。
Half of the top-level settings elements are simple values, representing a range of values which describe elements of the build system that are active full-time.
顶层设置的一半元素都是简单的值,其代表了用于构建系统的全局值。
${user.home}/.m2/repository
true
false
false
...
This element contains a list of pluginGroup elements, each contains a groupId.The list is searched when a plugin is used and the groupId is not provided in the command line.This list automatically containsorg.apache.maven.plugins and org.codehaus.mojo.
这个元素包含了很多pluginGroup元素,每一个都包含一个groupId。当使用一个插件并且并没有在命令行指定其groupId时便会搜索这个列表。这个列表中自动包含org.apache.maven.plugins和org.codehaus.mojo。
...
org.mortbay.jetty
...
For example, given the above settings the Maven command line may executeorg.mortbay.jetty:jetty-maven-plugin:run with the truncated command:
例如,鉴于上述设置,Maven控制台可以通过简短命令来执行org.mortbay.jetty:jetty-maven-plugin:run命令:
mvn jetty:run
The repositories for download and deployment are defined by the repositories anddistributionManagementelements of the POM. However, certain settings such asusername andpassword should not be distributed along with the pom.xml. This type of information should exist on the build server in thesettings.xml.
通过POM的repositories和distributionManagement元素来定义下载和部署仓库。然而,某些设置,诸如用户名和密码不应该随着pom.xml分布。这种类型的信息应该存放在构建服务器的settings.xml文件中。
...
server001
my_login
my_password
${user.home}/.ssh/id_dsa
some_passphrase
664
775
...
Note: If you use a private key to login to the server, make sure you omit the
注意:如果您使用私钥登录到服务器,请确保您忽略了
Password Encryption
A new feature - server password and passphrase encryption has been added to 2.1.0+. See detailson this page
...
planetmirror.com
PlanetMirror Australia
http://downloads.planetmirror.com/pub/maven2
central
...
For a more in-depth introduction of mirrors, please read the Guide to Mirror Settings.
...
myproxy
true
http
proxy.somewhere.com
8080
proxyuser
somepassword
*.google.com|ibiblio.org
...
The profile element in the settings.xml is a truncated version of thepom.xml profile element. It consists of theactivation, repositories, pluginRepositories andproperties elements. The profileelements only include these four elements because they concerns themselves with the build system as a whole (which is the role of thesettings.xmlfile), not about individual project object model settings.
settings.xml文件中的profile元素是一个简短的pom.xml中的profile版本。其包含了activation, repositories, pluginRepositories和properties元素。这个profile元素只包含了这四个元素,这是因为其关心的是整个系统的建立(这是settings.xml文件的作用),而不是关于单个项目对象模型的设置。
If a profile is active from settings, its values will override any equivalently ID’d profiles in a POM orprofiles.xml file.
Activations are the key of a profile. Like the POM’s profiles, the power of a profile comes from its ability to modify some values only under certain circumstances; those circumstances are specified via anactivation element.
...
test
false
1.5
Windows XP
Windows
x86
5.1.2600
mavenVersion
2.0.3
${basedir}/file2.properties
${basedir}/file1.properties
...
...
Activation occurs when all specified criteria have been met, though not all are required at once.
The activation element is not the only way that a profile may be activated. The settings.xml file’s activeProfile element may contain the profile’s id. They may also be activated explicitly through the command line via a comma separated list after the -P flag (e.g. -P test).
To see which profile will activate in a certain build, use the maven-help-plugin.
mvn help:active-profiles
Maven properties are value placeholder, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. They come in five different styles, all accessible from the settings.xml file:
...
...
${user.home}/our-project
...
...
The property ${user.install} is accessible from a POM if this profile is active.
Repositories are remote collections of projects from which Maven uses to populate the local repository of the build system. It is from this local repository that Maven calls it plugins and dependencies. Different remote repositories may contain different projects, and under the active profile they may be searched for a matching release or snapshot artifact.
...
...
codehausSnapshots
Codehaus Snapshots
false
always
warn
true
never
fail
http://snapshots.maven.codehaus.org/maven2
default
...
...
...
Repositories are home to two major types of artifacts. The first are artifacts that are used as dependencies of other artifacts. These are the majority of plugins that reside within central. The other type of artifact is plugins. Maven plugins are themselves a special type of artifact. Because of this, plugin repositories may be separated from other repositories (although, I have yet to hear a convincing argument for doing so). In any case, the structure of the pluginRepositories element block is similar to the repositories element. The pluginRepository elements each specify a remote location of where Maven can find new plugins.
...
env-test
The final piece of the settings.xml puzzle is the activeProfiles element. This contains a set of activeProfile elements, which each have a value of a profile id. Any profile id defined as an activeProfile will be active, reguardless of any environment settings. If no matching profile is found nothing will happen. For example, if env-test is an activeProfile, a profile in a pom.xml (or profile.xml with a corrosponding id will be active. If no such profile is found then execution will continue as normal.