作者也在正在不断学习的过程中,如果有不正确的地方,热烈欢迎指正,感谢~
此文章会随作者的理解随时更新。
Maven settings .xml 文件翻译
<?xml version="1.0" encoding="UTF-8"?>
<!--
| 这个是maven的配置文件,它可以在两种级别生效
|
| 1. 用户级别。settting.xml 文件可以给单个用户提供配置,
| 用户级别配置文件通常位于${user.home}/.m2/settings.xml.
| 注意:这个位置的配置可以用以下命令覆盖:
| -s /path/to/user/settings.xml
|
| 2. 全局级别。setting.xml文件给在同一台机器上的全部用户和项目提供配置(假设使用同样的maven安装)
| 全局级别配置文件通常位于${maven.conf}/settings.xml.
| 注意:这个位置的配置可以用以下命令覆盖:
| -gs /path/to/global/settings.xml
|
| 此文件中提供了大部分的默认配置,当没有指定setting配置文件时,使用该文件中的默认值。
| 以使你能够在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">
<!-- localRepository
| 这个路径指定了maven的本地仓库地址,默认为:${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!-- interactiveMode
| Maven是否需要和用户交互以获得输入。
| 如果设置为false,当有参数需要用户指定时,maven将提供一个合理的默认值,或者基于其他设置。
| 默认: true
<interactiveMode>true</interactiveMode>
-->
<!-- offline
| 决定maven是否需要在离线模式下构建(build)
| 默认: false
<offline>false</offline>
-->
<!-- pluginGroups
| 默认情况下,当运行"mvn prefix:goal"时,maven只会在"org.apache.maven.plugins"和"org.codehaus.mojo"下搜索插件。
| 当有自定义插件时,可以将包名定义在此,增加搜索范围
|-->
<pluginGroups>
<!-- pluginGroup
| 指定包名使其能搜索相应插件
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<!-- 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
| 指定网络代理
<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
| 用户授权管理列表,当链接maven私服时,从这里读取授权信息。
| 用id标记一个私服
| 提示: username/password 或者 privateKey/passphrase 需要成对出现
|-->
<servers>
<!-- server
| 为指定的私服配置权限信息,用id这个属性确定一个唯一的系统
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- 也可以使用key的方式验证信息
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
<!-- mirrors
| 这个列表用来配置私服的镜像站点,
| 主要用来解决从中央仓库或者私服下载网速慢,服务器网络波动等问题。
| 镜像需要有一个唯一的id,和profile.repository.id相照应。
| mirrorOf标签用来指定是哪个仓库的镜像源,和profile.repository.id属性相对应。
| 中央仓库的profile.repository.id默认值是central
|-->
<mirrors>
<!-- mirror
| id 值必须是唯一的
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors>
<!-- profiles
| 根据环境参数来调整构建配置的列表。settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。
| 它包含了id,activation, repositories, pluginRepositories和 properties元素。
| 这里的profile元素只包含这五个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。
| 如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同id的profile。
|
| 举个例子,当你在不同的JDK版本下有不同的需求时,你可以设置不同的profile
|-->
<profiles>
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>
maven setting.xml 文件内部标签之间的关系说明
Maven配置里repositories、mirrors、servers之间的关系
- repositories里指定要用到的远程仓库,包括远程仓库的唯一标识、地址、名称、怎么用(比如是否可以拉SnapShot的依赖),这里可以多指定一些仓库,maven找依赖的时候,如果本地仓库没有,就在这些远程仓库里从上往下找,找到就下载,全找完还找不到就是找不到了
- mirrors里指定的是仓库的代理,通过在mirrorOf里指定要代理的仓库(可以直接指定,也可以用一些匹配符来指定),来代理向远程仓库发起的请求,如果repositories里的仓库id被mirrorOf匹配到了,那么maven向这个仓库发的请求,就被mirrors规则代理到其他URL了
- servers里定的是身份认证信息,因为一般私服都要用户名和密码,不然不安全,所以看一在这里指定用户名和密码,repository里的id匹配到servers里的id从而找到用户名和密码来访问repository
附录
maven国内常用镜像
- 阿里云镜像源
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>