Maven配置文件setting.xml的关键说明

转载:https://blog.csdn.net/u012562943/article/details/61916067

第一步:看settings.xml的内容解释
<!-- 
| #用户级别,面向单个用户配置,即每个用户都可以自定义settings.xml供己方使用 
| This is the configuration file for Maven. It can be specified at two levels: 
| 1. User Level. This settings.xml file provides configuration for a single user, 
| |#其中的CLI选项指的是mvn操作命令的相关参数比如:mvn -v 
| and is normally provided in ${user.home}/.m2/settings.xml. 
| NOTE: This location can be overridden with the CLI option: 
| #全局级别,即面向所有用户同一配置 
| | -s /path/to/user/settings.xml 
| 2. Global Level. This settings.xml file provides configuration for all Maven 
| users on a machine (assuming they're all using the same Maven | installation). It's normally provided in 
| ${maven.home}/conf/settings.xml. | | NOTE: This location can be overridden with the CLI option: 
| | -gs /path/to/global/settings.xml 
| | The sections in this sample file are intended to give you a running start at 
| getting the most out of your Maven installation. Where appropriate, the default 
| values (values used when the setting is not specified) are provided. 
-->
明白settings.xml具有两个级别:用户级别和全局级别
settings.xml配置文件属于maven的相关配置,配置的是其他工程项目pom.xml中的全局配置
第二步:了解settings.xml标准参数结构
localRepository 本地仓库配置路径 interactiveMode 是否交互式输入提醒。默认true offline 是否每次编译部署时候需要联网,默认false pluginGroups 插件组合,供编译时选用 proxies 代理配置,连接本地无法远程的网络 servers 服务配置,上传构件/连接仓库所用 mirrors 替代有网络问题的repository的访问站点 profiles 应用于不同环境的配置 activeProfiles 激活指定的配置,与profile搭配使用
第三步:详解以上的参数含义
localRepository 保存远程下载的构建的本地位置,采用绝对路径,默认存放在${user.home}/.m2/repository
<!-- 
localRepository 
| The path to the local repository maven will use to store artifacts. 
| | Default: ${user.home}/.m2/repository
-->
interactiveMode 交互式节点配置,默认为true,设置为false则会在mvn执行中使用默认的参数设置交互性问题,建议设置为true
<!-- 
interactiveMode 
| This will determine whether maven prompts you when it needs input. If set to false, 
| maven will use a sensible default value, perhaps based on some other setting, for 
| the parameter in question. 
| | Default: true
-->
offline 是否每次的编译部署都需要联网,默认为false。如果构件不需要更新下载则可设置为true,提高build效率、成功率。
<!-- 
offline 
| Determines whether maven should attempt to connect to the network when executing a build. 
| This will have an effect on artifact downloads, artifact deployment, and others. 
| | Default: false
-->
pluginGroups 插件组,默认包含maven插件、mojo插件,用于插件在使用时没有指定groupId时,这个列表就会被搜索。
<!-- 
pluginGroups 
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. 
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers 
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. 
-->
示例:mvn jetty run替代org.morbay.jetty:jetty-maven-plugin:run
<pluginGroups> 
<pluginGroup> org.mortbay.jetty </pluginGroup> 
</pluginGroups>
proxies 代理配置,默认第一个proxy配置起效
<!-- 
proxies 
| This is a list of proxies which can be used on this machine to connect to the network. 
| Unless otherwise specified (by system property or command-line switch), the first proxy 
| specification in this list marked as active will be used. 
--> 
<proxies> 
<!-- 
proxy 新增一个代理配置示例 
| Specification for one proxy, to be used in connecting to the network. 
| <proxy> 
<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>
servers配置,上传构件需要验证的server配置,通过id来应用,与mirror/repository标签的id相一致
<!-- 
servers 
| This is a list of authentication profiles, keyed by the server-id used within the system. 
| Authentication profiles can be used whenever maven must make a connection to a remote server. 
--> 
<servers> 
<!-- 
server 
| Specifies the authentication information to use when connecting to a particular server, identified by 
| a unique name within the system (referred to by the 'id' attribute below). 
| | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are 
| used together. 
| <server> 
<id>deploymentRepo</id> 
<username>repouser</username> 
<password>repopwd</password> 
</server>
-->
<!-- Another sample, using keys to authenticate. 
<server> 
<id>siteServer</id> 
<privateKey>/path/to/private/key</privateKey> 
<passphrase>optional; leave empty if not used.</passphrase> 
</server> 
</servers>
mirrors 构建镜像,替代有网络问题的repository的访问站点,即当下载的maven构建有问题时可通过此配置替换原有的下载地址
<!-- 
mirrors 
| This is a list of mirrors to be used in downloading artifacts from remote repositories. 
| | It works like this: a POM may declare a repository to use in resolving certain artifacts. 
| However, this repository may have problems with heavy traffic at times, so people have mirrored 
| it to several places. | | That repository definition will have a unique id, so we can create a mirror reference for that 
| repository, to be used as an alternate download site. The mirror site will be the preferred 
| server for that repository. //central代表maven官网的中央仓库 
-->
示例:
<mirror> 
<id>mirrorId</id> 
#指定替代的唯一仓库id或者*代表所有都替代,支持多仓库id,以逗号分隔 
<mirrorOf>repositoryId/*</mirrorOf>
<name>Human Readable Name for this Mirror.</name> 
#镜像url 
<url>http://my.repository.com/repo/path</url>
</mirror>
profiles 多条件集合配置,用于不同条件下可应用不同的配置,其中也可配置自定义的repository/pluginRepository
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. 
<profile> 
#唯一id 
<id>jdk-1.4</id>
#在此配置的任何一个节点条件满足则触发此配置 
<activation>
<jdk>1.4</jdk> 
</activation> 
<repositories> 
<repository> 
#与server的id一致 
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</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://www.myhost.com/maven/jdk14</url> 
<layout>default</layout> 
<snapshotPolicy>always</snapshotPolicy> 
</repository> 
</repositories>
</profile>
-->
activeProfiles 激活相应的profile配置,可激活多个配置
activeProfiles //List of profiles that are active for all builds. 
  <activeProfiles> 
<activeProfile>alwaysActiveProfile</activeProfile> 
<activeProfile>anotherAlwaysActiveProfile</activeProfile> 
  </activeProfiles>
distributionManagement(新增) 上传构件
<distributionManagement> 
<repository> 
#对应发布版本的server.id 
<id>release_server</id>
<url></url> 
</repository> 
<snapshotRepository> 
#对应快照版本的server.id
<id>snapshot_server</id>
<url></url> 
</snapshotRepository>
repositories(新增) 统一的下载仓库
<repositories> 
<repository>
#对应server.id 
<id>snapshot</id> 
#下载构件的仓库url 
<url></url>
<releases> 
#不支持发布版本的查询
<enabled>false</enabled>
</releases> 
<snapshots> 
#支持快照版本的查询 
<enabled>true</enabled>
</snapshots> 
</repository> 
</repositories>
总结
mirror是下载构件的配置,其中的id属性在其下载构件需要server验证时候对应的server.id
mirror的优先级高于repository
distributionManagement是用在上传构件到远程服务器的配置,其中的repository配置中的id也对应server.id,毕竟上传构件需要server验证

猜你喜欢

转载自blog.csdn.net/qq_39416311/article/details/80866820