以maven 3.0.4版本为例:
conf/setting.xml
1 |
<? xml version = "1.0" encoding = "UTF-8" ?> |
2 |
3 |
< settings xmlns = "http://maven.apache.org/SETTINGS/1.0.0" |
4 |
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" |
5 |
xsi:schemaLocation = "http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" > |
6 |
<!--指定本地仓库存储路径。默认值为~/.m2/repository 即 ${user.home}/.m2/repository。 --> |
7 |
< localRepository >d:/.m2/repository</ localRepository > |
8 |
9 |
<!--指定Maven是否需要和用户输入进行交互。true:需要与用户交互;false:使用一个合理的默认值。默认值为true。 --> |
10 |
< interactiveMode >true</ interactiveMode > |
11 |
12 |
<!--指定是否使用plugin-registry.xml文件来管理插件版本。设为true表示使用。默认值为false。--> |
13 |
< usePluginRegistry >false</ usePluginRegistry > |
14 |
15 |
<!--指定是否在离线模式下运行。设为true表示项目构建要在离线模式下运行,默认值为false。 --> |
16 |
< offline >false</ offline > |
17 |
18 |
<!-- 指定插件groupId列表,用于搜索时插件的groupId没有明确规定。 --> |
19 |
< pluginGroups > |
20 |
<!-- 指定使用插件查找进一步的组标识符 --> |
21 |
< pluginGroup >com.micmiu.plugins</ pluginGroup > |
22 |
</ pluginGroups > |
23 |
24 |
<!-- 指定这台机器连接到网络的代理服务器的列表。除非另有规定(系统属性或命令行开关), |
25 |
列表中配置的第一代理将被激活使用。--> |
26 |
< proxies > |
27 |
<!-- 配置代理服务器的相关参数 --> |
28 |
< proxy > |
29 |
<!-- 代理标识ID,默认值:default --> |
30 |
< id >micmiuProxy</ id > |
31 |
<!-- 指定是否激活,默认值:true --> |
32 |
< active >true</ active > |
33 |
<!-- 指定代理协议,默认值:http --> |
34 |
< protocol >http</ protocol > |
35 |
<!-- 指定代理认证的用户名 --> |
36 |
< username >micmiu</ username > |
37 |
<!-- 指定代理认证用户的密码 --> |
38 |
< password >mypwd</ password > |
39 |
<!-- 指定代理服务器的主机名 --> |
40 |
< host >micmiu.com</ host > |
41 |
<!-- 指定代理服务的端口 默认值:8080 --> |
42 |
< port >80</ port > |
43 |
<!-- 指定不被代理的主机名列表。多个用|分隔。--> |
44 |
< nonProxyHosts >ctosun.com|ctosun.micmiu.com</ nonProxyHosts > |
45 |
</ proxy > |
46 |
</ proxies > |
47 |
48 |
<!-- 这是一个认证配置的列表,系统内部根据配置的serverID使用。认证配置用于maven链接到远程服务--> |
49 |
< servers > |
50 |
<!-- 指定的身份认证信息用于连接到一个特定的服务器时,确定系统内的唯一的名称(简称下面的'id'属性)。--> |
51 |
< server > |
52 |
<!-- 这是server的id(注意不是用户登陆的id)。该id与distributionManagement中repository元素的id必须要匹配。--> |
53 |
< id >micmiu-releases</ id > |
54 |
<!-- 服务器认证的用户名 --> |
55 |
< username >michael</ username > |
56 |
<!-- 服务器认证的用户对应的密码 --> |
57 |
< password >mypwd</ password > |
58 |
</ server > |
59 |
60 |
<!-- 另一个示例 私钥/密码 --> |
61 |
< server > |
62 |
< id >micmiu-snapshots</ id > |
63 |
<!-- 认证时使用的私钥文件。 --> |
64 |
< privateKey >/home/micmiu/.ssh/id_dsa</ privateKey > |
65 |
<!-- 认证时使用的私钥密码,没有密码就设为空 --> |
66 |
< passphrase >mypwd</ passphrase > |
67 |
<!-- 目录被创建时的权限设置。其值对应了unix文件系统的权限,如664,或者775 --> |
68 |
< directoryPermissions >775</ directoryPermissions > |
69 |
<!-- 仓库文件创建时的权限设置。其值对应了unix文件系统的权限,如664,或者775。 --> |
70 |
< filePermissions >664</ filePermissions > |
71 |
</ server > |
72 |
</ servers > |
73 |
74 |
<!-- 指定镜像列表,用于从远程仓库下载资源 --> |
75 |
< mirrors > |
76 |
<!-- 指定仓库的镜像站点,代替一个给定的库。该镜像藏库有一个ID相匹配的mirrorOf元素。 |
77 |
ID是用于继承和直接查找目的,必须是唯一的。--> |
78 |
< mirror > |
79 |
<!--该镜像的唯一标识符。id用来区分不同的mirror元素。 --> |
80 |
< id >mirrorId</ id > |
81 |
<!--被镜像的服务器的id,比如:central,不能和id匹配。--> |
82 |
< mirrorOf >central</ mirrorOf > |
83 |
< name >micmiu for dev.</ name > |
84 |
< url >http://dev.micmiu.com/repo/maven2</ url > |
85 |
</ mirror > |
86 |
87 |
</ mirrors > |
88 |
89 |
<!-- 这是一个可以在各种不同的方式激活的配置文件列表,并可以修改构建过程。在settings.xml中提供的信息, |
90 |
旨在提供本地机器允许建立在本地环境中工作的具体路径和库位置。有多种方式可以激活配置属性:一种在settings.xml中<activeProfiles>指定; |
91 |
另一种实质上依赖于系统属性,无论是匹配特定的属性值或只是测试到它的存在.配置文件也可以根据JDK版本的前缀进行激活,1.4 可以激活1.4.2_07 |
92 |
注:对于在settings.xml中定义的配置,你仅限于指定资源仓库、插件仓库和用于插件在POM中变量的自由形式属性的定义 --> |
93 |
< profiles > |
94 |
<!-- 指定生成过程的介绍,使用一个或多个上述机制被激活。对于继承而言,激活通过<activatedProfiles/>或命令行配置文件, |
95 |
配置文件必须有一个唯一的ID。此配置文件的例子使用的JDK版本触发激活。--> |
96 |
< profile > |
97 |
<!--该配置的唯一标识符。 --> |
98 |
< id >jdk-1.4</ id > |
99 |
100 |
<!--自动触发配置文件的逻辑定义。Activation的逻辑配置决定了是否开启该profile。activation元素并不是激活profile的唯一方式。 |
101 |
settings.xml文件中的activeProfile元素可指定需要激活的profile的id。 |
102 |
profile也可以通过在命令行,使用-P标记和逗号分隔的列表来显式的激活 --> |
103 |
< activation > |
104 |
<!--指定是否激活的标识 默认值为false--> |
105 |
< activeByDefault >false</ activeByDefault > |
106 |
107 |
<!--当匹配的jdk被检测到,profile被激活。例如,1.4激活JDK1.4,1.4.0_2,而!1.4激活所有不是以1.4开头的JDK版本。--> |
108 |
< jdk >1.4</ jdk > |
109 |
110 |
<!-- 当检测到匹配的操作系统属性时,指定该配置文件将被激活, --> |
111 |
< os > |
112 |
<!--激活profile的操作系统的名字 --> |
113 |
< name >windows 7</ name > |
114 |
<!--激活profile的操作系统所属家族(如 'windows') --> |
115 |
< family >windows</ family > |
116 |
<!--激活profile的操作系统体系结构 --> |
117 |
< arch >x86</ arch > |
118 |
<!--激活profile的操作系统版本--> |
119 |
< version >6.1</ version > |
120 |
</ os > |
121 |
122 |
<!-- 检测系统对应的属性和值(该值可在POM中通过${属性名称}引用),配置就会被激活。 |
123 |
如果值字段是空的,那么存在属性名称字段就会激活 --> |
124 |
< property > |
125 |
<!-- 属性的名称 --> |
126 |
< name >mavenVersion</ name > |
127 |
<!-- 属性的值 --> |
128 |
< value >3.0.4</ value > |
129 |
</ property > |
130 |
<!-- 通过检测该文件的是否存在来激活配置。missing检查文件是否存在,如果不存在则激活profile;exists则会检查文件是否存在,如果存在则激活。--> |
131 |
< file > |
132 |
<!--如果指定的文件存在,则激活profile。 --> |
133 |
< exists >/usr/local/micmiu/workspace/myfile</ exists > |
134 |
<!--如果指定的文件不存在,则激活profile。--> |
135 |
< missing >/usr/local/micmiu/workspace/myfile</ missing > |
136 |
</ file > |
137 |
</ activation > |
138 |
139 |
<!-- 对应profile的扩展属性列表。Maven属性和Ant中的属性一样,可以用来存放一些值。这些值可以在POM中的任何地方使用标记${X}来使用, |
140 |
这里X是指属性的名称。属性有五种不同的形式,并且都能在settings.xml文件中访问。 |
141 |
1. env.X: 表示系统环境变量。例如,"env.PATH" 等同于 $path环境变量(在Windows上是%PATH%)。 |
142 |
2. project.x:表示 POM中对应的属性值。 |
143 |
3. settings.x: 表示 settings.xml中对应属性值。 |
144 |
4. Java系统属性: 所有可通过java.lang.System.getProperties()访问的属性都能在POM中使用该形式访问。 |
145 |
5. x: 在<properties/>元素中,或者外部文件中设置,以${someVar}的形式使用。 --> |
146 |
< properties > |
147 |
< user.blog >www.micmiu.com</ user.blog > |
148 |
</ properties > |
149 |
150 |
</ profile > |
151 |
152 |
<!-- 这是另一个配置文件,根据系统属性来激活 --> |
153 |
< profile > |
154 |
<!--该配置的唯一标识符。 --> |
155 |
< id >env-dev</ id > |
156 |
< activation > |
157 |
< property > |
158 |
<!-- 被用来激活配置文件的属性的名称 --> |
159 |
< name >target-env</ name > |
160 |
<!-- 被用来激活配置文件的属性的值 --> |
161 |
< value >dev</ value > |
162 |
</ property > |
163 |
</ activation > |
164 |
<!-- 指定配置文件的扩展配置 内容采取property.value的形式 --> |
165 |
< properties > |
166 |
< tomcatPath >/path/to/tomcat/instance</ tomcatPath > |
167 |
</ properties > |
168 |
</ profile > |
169 |
170 |
< profile > |
171 |
< id >repo-dev</ id > |
172 |
<!-- 配置远程仓库列表 --> |
173 |
< repositories > |
174 |
<!-- 远程仓库的配置信息 --> |
175 |
< repository > |
176 |
<!-- 远程仓库唯一标识--> |
177 |
< id >nexus</ id > |
178 |
<!-- 远程仓库名称 --> |
179 |
< name >nexus for develop</ name > |
180 |
<!-- 远程仓库URL --> |
182 |
< layout >default</ layout > |
183 |
< releases > |
184 |
<!--是否使用这个资源库下载这种类型的构件 默认值:true--> |
185 |
< enabled >true</ enabled > |
186 |
<!--指定下载更新的频率。这里的选项是:always(一直),daily(每日,默认值),interval:X(这里X是指分钟),或者never(从不)。 --> |
187 |
< updatePolicy >daily</ updatePolicy > |
188 |
<!--当Maven验证构件校验文件失败时该怎么做fail(失败)或者warn(告警)。--> |
189 |
< checksumPolicy >warn</ checksumPolicy > |
190 |
</ releases > |
191 |
< snapshots > |
192 |
<!--是否使用这个资源库下载这种类型的构件 默认值:true--> |
193 |
< enabled >true</ enabled > |
194 |
<!--指定下载更新的频率。这里的选项是:always(一直),daily(每日,默认值),interval:X(这里X是指分钟),或者never(从不)。 --> |
195 |
< updatePolicy >daily</ updatePolicy > |
196 |
<!--当Maven验证构件校验文件失败时该怎么做fail(失败)或者warn(告警)。--> |
197 |
< checksumPolicy >warn</ checksumPolicy > |
198 |
</ snapshots > |
199 |
</ repository > |
200 |
</ repositories > |
201 |
< pluginRepositories > |
202 |
< pluginRepository > |
203 |
< id >nexus</ id > |
204 |
< name >local nexus</ name > |
206 |
< layout >default</ layout > |
207 |
< releases > |
208 |
< enabled >true</ enabled > |
209 |
</ releases > |
210 |
< snapshots > |
211 |
< enabled >true</ enabled > |
212 |
</ snapshots > |
213 |
</ pluginRepository > |
214 |
</ pluginRepositories > |
215 |
</ profile > |
216 |
217 |
</ profiles > |
218 |
219 |
<!-- 指定被激活的配置文件--> |
220 |
< activeProfiles > |
221 |
< activeProfile >repo-dev</ activeProfile > |
222 |
</ activeProfiles > |
223 |
</ settings > |
官方参考文档:http://maven.apache.org/ref/3.0.4/maven-settings/settings.html
转自:http://www.micmiu.com/software/build/maven-setting-xml/