maven默认的settings.xml是一个包含注释和例子的模板,能够快速的修改settings.xml文件java
maven安装后不会在用户目录下自动生成settings.xml,通常是将/maven/conf下的settings.xml文件拷贝过去进行相应的修shell
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- 本地仓库的路径,默认值是~/.m2/repository --> <localRepository>/path/to/local/repo</localRepository> <!-- maven是否须要和用户交互,默认值是true --> <interactiveMode>true</interactiveMode>
<!-- 是否使用plugin-registry.xml文件来管理插件版本 -->
<usePluginRegistry>false</usePluginRegistry>
<!--
maven是否须要在离线模式下运行
true:通常用于构建服务器不能链接远程仓库的时候,基于网络或者安全考虑
默认为false -->
<offline>false</offline> <!--
当插件的组织ID(groupId)没有提供的时候,供搜寻插件组织的列表
包含<pluginGroup>元素列表,每个子元素包含一个组织ID(groupId)
默认包含org.apache.maven.plugins --> <pluginGroups> <!-- plugin的组织ID(groupId) --> <pluginGroup>com.your.plugins</pluginGroup> </pluginGroups> <!-- 配置多种代理,包含<proxy>元素 --> <proxies> <!-- 配置代理时须要的信息 --> <proxy>
<!-- 代理惟一id,用于区分不一样的代理 --> <id>optional</id>
<!-- 代理是否激活 --> <active>true</active>
<!-- 代理的协议 --> <protocol>http</protocol>
<!-- 代理的用户名,表示代理服务器认证的登陆名/密码 --> <username>proxyuser</username>
<!-- 代理的密码 --> <password>proxypass</password>
<!-- 代理的主机名 --> <host>proxy.host.net</host>
<!-- 代理的端口 --> <port>80</port>
<!-- 不被代理的主机名列表 --> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies> <!-- 配置服务端的设置,包含server元素--> <servers> <!-- 包含配置服务器是须要的信息 --> <server>
<!-- server的id,与distributionManagement中repository的id相匹配 --> <id>deploymentRepo</id>
<!-- 鉴权用户名,表示服务器认证须要的用户名/密码 --> <username>repouser</username>
<!-- 鉴权密码 --> <password>repopwd</password>
<!-- 鉴权时使用的私钥位置,私钥位置和私钥密码指定一个私钥的路径(默认是/home/hudson/.ssh/id_dsa) --> <privateKey>/path/to/private/key</privateKey>
<!-- 鉴权时使用的私钥密码 --> <passphrase>optional; leave empty if not used.</passphrase>
<!--
文件被建立时的权限,若是在部署的时候会建立一个仓库文件或者目录,这时须要使用权限
该元素的合法值是一个三位数字,对应unix文件系统的权限 -->
<filePermissions>664</filePermissions>
<!-- 目录建立时的权限 -->
<directoryPermissions>775</directoryPermissions>
<!-- 传输层的额外配置项 -->
<configuration></configuration> </server> </servers> <!-- 下载的镜像列表 --> <mirrors> <!-- 镜像信息 --> <mirror>
<!-- 镜像惟一标识 --> <id>mirrorId</id>
<!-- --> <mirrorOf>repositoryId</mirrorOf>
<!-- 镜像名称 --> <name>Human Readable Name for this Mirror.</name>
<!-- 镜像URL --> <url>http://my.repository.com/repo/path</url> </mirror> </mirrors> <!--
根据环境参数来调整构建配置的列表
settings.xml中的profiles是pom.xml中profiles的裁剪版
包含<id>,<activation>,<repository>,<pluginRepository>,<properties>元素
settings.xml中的profiles只包含这几个元素是由于settings.xml文件只关心构建系统的总体而非单独的项目对象模型设置
若是一个profile被激活,它的值会覆盖任何其定义在pom.xml或profile.xml中相同id的profile -->
<profiles> <!-- 根据环境参数调整构建配置 --> <profile>
<!-- 该配置的惟一标识 --> <id>jdk-1.4</id>
<!--
自动触发profile的逻辑条件
和pom.xml中的profile同样,在特定的环境中自动使用某些特定的值
这些特定的值经过activation指定 -->
<activation>
<!-- profile默认是否激活,默认false -->
<activeByDefault>false</activeByDefault>
<!-- activation有一个java版本检测,若是检测的版本与当前配置一致则profile被激活 --> <jdk>1.4</jdk>
<!-- 当匹配的操做系统属性被检测到时,profile被激活 -->
<os>
<!-- 操做系统名称 -->
<name>Windows XP</name>
<!-- 操做系统所属的家族 -->
<family>Windows</family>
<!-- 操做系统体系结构 -->
<arch>x86</arch>
<!-- 操做系统版本 -->
<version>5.1.2600<version>
</os>
<!-- 属性检测,若是拥有对应的名称和值,profile将会被激活 -->
<property>
<!-- 激活profile的属性名称 -->
<name>mavenVersion</name>
<!-- 激活profile的值 -->
<value>2.0.3</value>
</property>
<!-- 经过检测文件是否存在激活profile -->
<file>
<!-- 文件存在则激活profile -->
<exists>/usr/local/min/workspace</exists>
<!-- 文件不存在则激活profile -->
<missing>/usr/local/min/workspace</missing>
</file>
</activation>
<!-- 远程仓库列表,是maven用来填充构建系统本地仓库所使用的一组远程项目 --> <repositories>
<!-- 远程仓库 --> <repository>
<!-- 远程仓库惟一标识 --> <id>jdk14</id>
<!-- 远程仓库名称 --> <name>Repository for JDK 1.4 builds</name>
<!-- 远程仓库url --> <url>http://www.myhost.com/maven/jdk14</url>
<!-- maven 2为仓库提供的默认布局,maven 1.x有另外一个不一样的布局,经过default/legacy指定 --> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories>
<!-- 插件远程仓库 -->
<pluginRepositories>
<pluginRepository>
<pluginRepository>
</pluginRepositories>
<!--
对应profile的扩展属性列表,和ant中的属性同样,能够用来存放值,这些值能够在pom的任何地方使用${x}访问,x指代属性名称
<env.x>:返回shell环境变量
<project.x>:指代pom对应的元素值
<settings.x>:指代settings.xml中对应的元素值
<x>:在<properties/>中或外部文件中使用${x}形式使用
-->
<properties>
<var>value</var>
</properties>
</profile>
</profiles>
<!-- 手动激活的profile列表 -->
<activeProfiles>
<!-- 若是有匹配的profile则pom.xml或者profile.xml中对应id的profile被激活 -->
<activeProfile>value</activeProfile>
</activeProfiles>
</settings>
主要元素有:激活<activation>,仓库<repositories>,插件仓库<pluginRepositories>,属性<properties>apache
一个项目能够设置多个profile,也能够在同一时间设置多个profile被激活安全
自动激活条件主要有:操做系统相关参数的判断,JDK版本的检查,属性值的检查,文件检查服务器
若是settings.xml中的profile被激活,则其值会覆盖pom.xml或profile.xml中同等id的profile网络