http://maven.apache.org/settings.html
The settings element in the settings.xml file contains elements used to define values which configure Maven execution in various ways, like the pom.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.
There are two locations where a settings.xml file may live:
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.
Here is an overview of the top elements under settings:
The contents of the settings.xml can be interpolated using the following expressions:
Note that properties defined in profiles within the settings.xml cannot be used for interpolation.
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 contains org.apache.maven.plugins and org.codehaus.mojo.
... ... org.mortbay.jetty
For example, given the above settings the Maven command line may execute org.mortbay.jetty:jetty-maven-plugin:run with the truncated command:
mvn jetty:run
The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with the pom.xml. This type of information should exist on the build server in the 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
A new feature - server password and passphrase encryption has been added to 2.1.0+. See details on 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 the pom.xml profile element. It consists of the activation, repositories, pluginRepositories and properties elements. The profile elements only include these four elements because they concerns themselves with the build system as a whole (which is the role of the settings.xml file), not about individual project object model settings.
If a profile is active from settings, its values will override any equivalently ID'd profiles in a POM or profiles.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 an activation 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.
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd">
http://zyl.iteye.com/blog/41612
maven2 比起maven1 来说,需要配置的文件少多了,主要集中在pom.xml和settings.xml中。
先来说说settings.xml,settings.xml对于maven来说相当于全局性的配置,用于所有的项目。在maven2中存在两个 settings.xml,一个位于maven2的安装目录conf下面,作为全局性配置。对于团队设置,保持一致的定义是关键,所以 maven2/conf下面的settings.xml就作为团队共同的配置文件。保证所有的团队成员都拥有相同的配置。当然对于每个成员,都需要特殊的 自定义设置,如用户信息,所以另外一个settings.xml就作为本地配置。默认的位置为:${user.dir} /.m2/settings.xml目录中(${user.dir} 指windows 中的用户目录)。
settings.xml基本结构如下:
简单介绍一下几个主要的配置因素:
localRepository:表示本地库的保存位置,也就是maven2主要的jar保存位置,默认在${user.dir}/.m2/repository,如果需要另外设置,就换成其他的路径。
offline:如果不想每次编译,都去查找远程中心库,那就设置为true。当然前提是你已经下载了必须的依赖包。
Servers
在POM中的 distributionManagement元素定义了开发库。然而,特定的username和pwd不能使用于pom.xml,所以通过此配置来保存server信息
Mirrors
表示镜像库,指定库的镜像,用于增加其他库
Proxies
此设置,主要用于无法直接访问中心的库用户配置。
Profiles
类似于pom.xml中的profile元素,主要包括activation,repositories,pluginRepositories 和properties元素
刚开始接触的时候,可能会比较迷惑,其实这是maven2中比较强大的功能。从字面上来说,就是个性配置。
单独定义profile后,并不会生效,需要通过满足条件来激活。
repositories 和pluginRepositories
定义其他开发库和插件开发库。对于团队来说,肯定有自己的开发库。可以通过此配置来定义。
如下的配置,定义了本地开发库,用于release 发布。
releases, snapshots:每个产品的版本的Release或者snapshot(注:release和snapshot的区别,release一般是比较稳定的版本,而snapshot基本上不稳定,只是作为快照)
properties
maven 的properties作为placeholder值,如ant的properties。
包括以下的5种类型值:
Activation
用于激活此profile
除了使用activation来激活profile,同样可以通过activeProfiles来激活
Active Profiles
表示激活的profile,通过profile id来指定。