maven setting.xml说明

来源:互联网 发布:淘宝客招募平台 编辑:程序博客网 时间:2024/06/16 01:26
settings.xml
https://maven.apache.org/settings.html

在两个地方存在:
1) $M2_HOME/conf/settings.xml--即安装目录的conf下
2) ${user.home}/.m2/settings.xml--即用户Home目录的.m2下
两个地方都存在的话,会融合到一起,相同的内容后者会将前者覆盖

整体结构

Quick Overview

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  <localRepository>  <interactiveMode>  <usePluginRegistry>  <offline>  <pluginGroups/>  <servers/>  <mirrors/>  <proxies/>  <profiles/>  <activeProfiles/></settings>
------------------------------

Simple Values

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  <localRepository>${user.home}/.m2/repository</localRepository>  <interactiveMode>true</interactiveMode>  <usePluginRegistry>false</usePluginRegistry>  <offline>false</offline>  ...</settings>
setting.xml中的内容可以引用系统的属性(如${user.home} ),以及环境变量(如${env.HOME}
-->localRepository--本地仓库地址,默认值是 ${user.home}/.m2/repository(windows下默认是C:\Users\用户名)
-->interactiveMode--当maven需要输入时,是否让maven提示你;默认是true,允许提示
-->usePluginRegistry--true,如果maven使用${user.home}/.m2/plugin-registry.xml文件来管理插件的版本,默认为false.(这个标签在m2中已经基本不用了)
-->offline--设置为ture,如果在脱机状态下运行maven,默认为false--由于网络设置问题或者安全原因而不能连接远端仓库时使用。
------------------------------

Plugin Groups

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <pluginGroups>    <pluginGroup>org.mortbay.jetty</pluginGroup>  </pluginGroups>  ...</settings>
pluginGroups包含pluginGroup元素的列表,每一个pluginGroup中包含一个groupId。在plugin被使用,同时groupId没有中命令行中被提供时,这个列表会被遍历。另外,该列表自动包含 org.apache.maven.plugins 和 org.codehaus.mojo
对于以上例子,mvn jetty:run相当于org.mortbay.jetty:jetty-maven-plugin:run 
------------------------------

Servers

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <servers>    <server>      <id>server001</id>      <username>my_login</username>      <password>my_password</password>      <privateKey>${user.home}/.ssh/id_dsa</privateKey>      <passphrase>some_passphrase</passphrase>      <filePermissions>664</filePermissions>      <directoryPermissions>775</directoryPermissions>      <configuration></configuration>    </server>  </servers>  ...</settings>
------
 repositories和 distributionManagement用于定义下载仓库和部署仓库。
id:server的ID,与maven试图连接的repository/mirror的id相对应。
username, password--登录server需要的认证信息
privateKeypassphrase--与上面一组类似,用于指定私钥和密码--password/passphrase暂时只支持用明文显示
filePermissionsdirectoryPermissions--一个被创建的仓库的权限设置
另外,使用privateKey登录server时,记得删除password。
------------------------------

Mirrors

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <mirrors>    <mirror>      <id>planetmirror.com</id>      <name>PlanetMirror Australia</name>      <url>http://downloads.planetmirror.com/pub/maven2</url>      <mirrorOf>central</mirrorOf>    </mirror>  </mirrors>  ...</settings>
id是mirror的唯一标志,name是该mirror的一个人性化的名称。在同mirror连接时,id用于区别不同的mirror,并从<servers>中找出相应的证书
url:mirror的基url。编译系统使用此url来连接一个仓库
mirrorOf:表示这是谁的mirror--(central=(http://repo.maven.apache.org/maven2/)))
------------------------------

Proxies

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <proxies>    <proxy>      <id>myproxy</id>      <active>true</active>      <protocol>http</protocol>      <host>proxy.somewhere.com</host>      <port>8080</port>      <username>proxyuser</username>      <password>somepassword</password>      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>    </proxy>  </proxies>  ...</settings>
id--proxy的唯一标识
active--该proxy是否可用,同一个时刻只能是一个可用
protocol,host,port-- protocol://host:port
usernamepassword:用于认证
nonProxyHosts:不能作为代理的host列表
------------------------------

Profiles

pom文件中profile的删减版,只包含activationrepositoriespluginRepositories 和properties 四种元素,因为这些都是与编译系统相关的,而不是与特定工程相关。
假如一个profile在setting.xml中是active的,它的值会覆盖掉任意pom文件及profile.xml中的相同id的profile

Activation

该标签的功能是profile文件的关键部分,它主要用于指定在哪些环境下需要修正一些值;如果指定的所有条件都满足,activation会被激活
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <profiles>    <profile>      <id>test</id>      <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>      ...    </profile>  </profiles>  ...</settings>

jdk:指定版本会被匹配到(如上, 1.5.0_06会被匹配到
os:指定os类型
property:如果指定的属性被检测到就满足(该propery可以是在pom中定义的)
file:满足exists/missing



Properties

可以用${X}的形式引用其它地方定义的变量,有如下五种情况:
1)env.X:返回shell命令的环境变量
2)project.x:引用工程中的“变量”,如<project><version>1.0</version></project>可以通过 ${project.version}引用
3)settings.x:引用setting.xml中的“变量”,如<settings><offline>false</offline></settings>可以通过 ${settings.offline}引用
4)Java System Properties:引用所有可以通过java.lang.System.getProperties()获得的属性,如${java.home}
5) x:引用<properties /> 定义的变量,如<properties>someVar</properties />可以${someVar}引用
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <profiles>    <profile>      ...      <properties>        <user.install>${user.home}/our-project</user.install>      </properties>      ...    </profile>  </profiles>  ...</settings>
如果profile是active的,那么 ${user.install}是可以从pom文件中访问到的
Repositories
用于标志一些远端的工程集合,maven可以使用这个工程来构成编译系统的本地仓库。maven从这个本地仓库来调用插件和依赖包。
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <profiles>    <profile>      ...      <repositories>        <repository>          <id>codehausSnapshots</id>          <name>Codehaus Snapshots</name>          <releases>            <enabled>false</enabled>            <updatePolicy>always</updatePolicy>            <checksumPolicy>warn</checksumPolicy>          </releases>          <snapshots>            <enabled>true</enabled>            <updatePolicy>never</updatePolicy>            <checksumPolicy>fail</checksumPolicy>          </snapshots>          <url>http://snapshots.maven.codehaus.org/maven2</url>          <layout>default</layout>        </repository>      </repositories>      <pluginRepositories>        ...      </pluginRepositories>      ...    </profile>  </profiles>  ...</settings>
releasessnapshots:可以决定用snapshot版本或者是releases版本
enabled:用来设置是否可用
updatePolicy:更新规则,可选的值有alwaysdaily (默认), interval:X (X是个表示分钟的整数) ,never
checksumPolicy:maven在部署文件到仓库的时候,也会部署其检验和文件,这个选择就是针对检验和出错时设置处理方式。对于缺失或者错误的检验和,可选的值有 ignorefail, or warn
layout:设置仓库的布局方式,可选值有default(maven 2默认的方式)、 legacy(maven 1.x的方式)

Plugin Repositories

仓库中包括两种类型的artifact,依赖包和插件。pluginRepositories和repositories的结构是类似的。

Active Profiles

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <activeProfiles>    <activeProfile>env-test</activeProfile>  </activeProfiles></settings>
activeProfiles可以将指定的id(如env-test)的profile设置为active。如果没有找到这个id的话,就什么也不做

Properties

可以用${X}的形式引用其它地方定义的变量,有如下五种情况:
1)env.X:返回shell命令的环境变量
2)project.x:引用工程中的“变量”,如<project><version>1.0</version></project>可以通过 ${project.version}引用
3)settings.x:引用setting.xml中的“变量”,如<settings><offline>false</offline></settings>可以通过 ${settings.offline}引用
4)Java System Properties:引用所有可以通过java.lang.System.getProperties()获得的属性,如${java.home}
5) x:引用<properties /> 定义的变量,如<properties>someVar</properties />可以${someVar}引用
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <profiles>    <profile>      ...      <properties>        <user.install>${user.home}/our-project</user.install>      </properties>      ...    </profile>  </profiles>  ...</settings>
如果profile是active的,那么 ${user.install}是可以从pom文件中访问到的
Repositories
用于标志一些远端的工程集合,maven可以使用这个工程来构成编译系统的本地仓库。maven从这个本地仓库来调用插件和依赖包。
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <profiles>    <profile>      ...      <repositories>        <repository>          <id>codehausSnapshots</id>          <name>Codehaus Snapshots</name>          <releases>            <enabled>false</enabled>            <updatePolicy>always</updatePolicy>            <checksumPolicy>warn</checksumPolicy>          </releases>          <snapshots>            <enabled>true</enabled>            <updatePolicy>never</updatePolicy>            <checksumPolicy>fail</checksumPolicy>          </snapshots>          <url>http://snapshots.maven.codehaus.org/maven2</url>          <layout>default</layout>        </repository>      </repositories>      <pluginRepositories>        ...      </pluginRepositories>      ...    </profile>  </profiles>  ...</settings>
releasessnapshots:可以决定用snapshot版本或者是releases版本
enabled:用来设置是否可用
updatePolicy:更新规则,可选的值有alwaysdaily (默认), interval:X (X是个表示分钟的整数) ,never
checksumPolicy:maven在部署文件到仓库的时候,也会部署其检验和文件,这个选择就是针对检验和出错时设置处理方式。对于缺失或者错误的检验和,可选的值有 ignorefail, or warn
layout:设置仓库的布局方式,可选值有default(maven 2默认的方式)、 legacy(maven 1.x的方式)

Plugin Repositories

仓库中包括两种类型的artifact,依赖包和插件。pluginRepositories和repositories的结构是类似的。

Active Profiles

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                      http://maven.apache.org/xsd/settings-1.0.0.xsd">  ...  <activeProfiles>    <activeProfile>env-test</activeProfile>  </activeProfiles></settings>
activeProfiles可以将指定的id(如env-test)的profile设置为active。如果没有找到这个id的话,就什么也不做
0 0
原创粉丝点击