目录
maven项目的setting.xml文件
一、Settings.xml文件的作用
它是用来设置Maven参数的配置文件。并且,settings.xml是Maven的全局配置文件。settings.xml中包含类似本地仓库、远程仓库和联网使用的代理信息等配置。
二、settings.xml文件的位置
Maven使用setting.xml文件来配置它本身的行为。这个文件通常位于Maven的conf目录下。通常默认位置是%USER_HOME%.m2\settings.xml
三、配置文件的优先级
局部配置优先于全局配置。
配置优先级从高到低:pom.xml> user settings > global settings
如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。如果全局配置和用户配置都存在,它们的内容将被合并,并且用户范围的settings.xml会覆盖全局的settings.xml。
四、元素预览
<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/>
LocalRepository
作用:该值表示构建系统本地仓库的路径。
其默认值:~/.m2/repository。
<localRepository>${user.home}/.m2/repository</localRepository>
InteractiveMode
作用:表示maven是否需要和用户交互以获得输入。
如果maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。
<interactiveMode>true</interactiveMode>
UsePluginRegistry
作用:maven是否需要使用plugin-registry.xml文件来管理插件版本。
如果需要让maven使用文件~/.m2/plugin-registry.xml来管理插件版本,则设为true。默认为false。
<usePluginRegistry>false</usePluginRegistry>
Offline
作用:这个属性表示在Maven进行项目编译和部署等操作时是否允许Maven进行联网来下载所需要的信息。
如果构建系统需要在离线模式下运行,则为true,默认为false。
当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。
<offline>false</offline>
PluginGroups
作用:当插件的组织id(groupId)没有显式提供时,供搜寻插件组织Id(groupId)的列表。
该元素包含一个pluginGroup元素列表,每个子元素包含了一个组织Id(groupId)。
<pluginGroups>
<!--plugin的组织Id(groupId) -->
<pluginGroup>com.your.plugins</pluginGroup>
</pluginGroups>
Servers
作用:仓库的下载和部署是在pom.xml文件中的repositories 和 distributionManagement 元素中定义的。然而,一般类似用户名、密码(有些仓库访问是需要安全认证的)等信息不应该在pom.xml文件中配置,这些信息可以配置在 settings.xml 中。
<servers>
<server>
<!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 -->
<id>releases</id>
<!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
<username>yu.dong</username>
<!--鉴权密码 。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
<password>Dd111111</password>
</server>
<server>
<id>siteServer</id>
<!--鉴权时使用的私钥位置。和前两个元素类似,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)。 -->
<privateKey>/path/to/private/key</privateKey>
<!--鉴权时使用的私钥密码。 -->
<passphrase>optional; leave empty if not used.</passphrase>
</server>
</servers>
Mirrors
作用:
<!-- 给定仓库的下载镜像。 -->
<mirror>
<!-- 该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
<id>mirrorId</id>
<!-- 被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo.maven.apache.org/maven2/)的镜像,就需要将该元素设置成central。这必须和中央仓库的id central完全一致。 -->
<mirrorOf>repositoryId</mirrorOf>
<!-- 镜像名称 -->
<name>Human Readable Name for this Mirror.</name>
<!-- 该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 -->
<url>http://my.repository.com/repo/path</url>
</mirror>
Proxies
作用:用来配置不同的代理。
<proxies>
<!--代理元素包含配置代理时需要的信息 -->
<proxy>
<!--代理的唯一定义符,用来区分不同的代理元素。 -->
<id>myproxy</id>
<!--该代理是否是激活的那个。true则激活代理。当我们声明了一组代理,而某个时候只需要激活一个代理的时候,该元素就可以派上用处。 -->
<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>
Profiles
作用:根据环境参数来调整构建配置的列表。
<profiles>
<profile>
<!-- profile的唯一标识 -->
<id>test</id>
<!-- 自动触发profile的条件逻辑 -->
<activation />
<!-- 扩展属性列表 -->
<properties />
<!-- 远程仓库列表 -->
<repositories />
<!-- 插件仓库列表 -->
<pluginRepositories />
</profile>
</profiles>
ActiveProfiles
作用:手动激活profiles的列表,按照profile被应用的顺序定义activeProfile。 该元素包含了一组activeProfile元素,每个activeProfile都含有一个profile id。任何在activeProfile中定义的profile id,不论环境设置如何,其对应的 profile都会被激活。如果没有匹配的profile,则什么都不会发生。
<activeProfiles>
<!-- 要激活的profile id -->
<activeProfile>env-test</activeProfile>
</activeProfiles>