Maven-官网翻译-使用仓库镜像
http://maven.apache.org/guides/mini/guide-mirror-settings.html
英文版本 2021-02-01
maven官网翻译之-使用仓库镜像-Using Mirrors for Repositories
With Repositories you specify from which locations you want to download certain artifacts, such as dependencies and maven-plugins. Repositories can be declared inside a project, which means that if you have your own custom repositories, those sharing your project easily get the right settings out of the box. However, you may want to use an alternative mirror for a particular repository without changing the project files.
从你指定的仓库(Repositories)中下载你所需要的artifacts,比如依赖(dependencies)、插件(maven-plugins)。可以在项目内部
声明仓库, 这意味着如果你有一些私人仓库,这意味着,如果你在项目内部
声明了仓库,那么你的项目分享出去,其他人就不用再单独对仓库进行设置了,就是开箱即用。在某些情况下,您可能希望对某些仓库使用你指定的备用的镜像仓库,而不用更改项目文件。
repository
美[rɪ'pɑzə.tɔri]英[rɪ'pɒzɪt(ə)ri]
n.〈英〉仓库;博物馆;店铺;墓室
网络存储库;资源库;套件库
location
美[loʊ'keɪʃ(ə)n]英[ləʊ'keɪʃ(ə)n]
n.位置;定位;地点;地方
网络地理位置;工作地点;场所
变形复数:locations;
certain
美['sɜrt(ə)n]英['sɜː(r)t(ə)n]
adj.肯定;确定;确信;无疑
pron.(不提及人或事物的名称时用)某些
网络确定的;肯定的;一定的
out of the box
网络开箱即用;开包即用;立即可用的
particular
美[pər'tɪkjələr]英[pə(r)'tɪkjʊlə(r)]
adj.讲究;挑剔;专指的;不寻常的
n.(正式记下的)细节;详细资料;详细介绍材料
网络特殊的;特别的;特定的
alternative
美[ɔl'tɜrnətɪv]英[ɔːl'tɜː(r)nətɪv]
adj.可供替代的;非传统的;另类的
n.可供选择的事物
网络替换物;非主流;两者挑一的
Some reasons to use a mirror are:
使用镜像的一些原因:
- There is a synchronized mirror on the internet that is geographically closer and faster
-
互联网上存在着某些仓库的同步镜像,地理位置与你更近,速度也就更快。
- You want to replace a particular repository with your own internal repository which you have greater control over
-
你想用你自己的内部仓库来替换一个特定的仓库,因为这样做的话,你有更大的控制权。
- You want to run a repository manager to provide a local cache to a mirror and need to use its URL instead
- 您想要运行仓库管理(repository manager)来提供镜像的本地缓存,and need to use its URL instead(没顺,todo)。
To configure a mirror of a given repository, you provide it in your settings file (${user.home}/.m2/settings.xml
), giving the new repository its own id
and url
, and specify the mirrorOf
setting that is the ID of the repository you are using a mirror of. For example, the ID of the main Maven Central repository included by default is central
, so to use the different mirror instance, you would configure the following:
要配置一个给定仓库的镜像,你需要修改你的设置文件 (${user.home}/.m2/settings.xml
)【用户级的】, 指明新的仓库的id
和url
,并把mirrorOf
设置为你要镜像的仓库的ID。 例如,默认包含的the main Maven Central 仓库的ID是 central
, 当我们要定义一个镜像仓库替换它时, 你可以像这样子配置:
<settings>
...
<mirrors>
<mirror>
<id>other-mirror</id>
<name>Other Mirror Repository</name>
<url>https://other-mirror.repo.other-company.com/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
...
</settings>
【附加】阿里的镜像:
https://maven.aliyun.com/mvn/guide
<settings>
...
<mirrors>
<mirror>
<id>aliyun-central-mirror</id>
<name>阿里云central</name>
<url>https://maven.aliyun.com/repository/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
...
</settings>
central仓和jcenter仓的聚合仓:
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
【附加】163镜像:
http://mirrors.163.com/.help/maven.html
<mirror>
<id>nexus-163</id>
<mirrorOf>*</mirrorOf>
<name>Nexus 163</name>
<url>http://mirrors.163.com/maven/repository/maven-public/</url>
</mirror>
Note that there can be at most one mirror for a given repository. In other words, you cannot map a single repository to a group of mirrors that all define the same <mirrorOf>
value. Maven will not aggregate the mirrors but simply picks the first match. If you want to provide a combined view of several repositories, use a repository manager instead.
请注意,一个仓库最多只能有一个镜像。换句话说,你不能将一个仓库映射到一组镜像(<mirrorOf>
都定义成一样的)。Maven不会对镜像进行聚合,只会简单的选择第一个匹配的镜像。如果你想要一个组合视图,由多个仓库组成,那么需要改用repository manager。
The settings descriptor documentation can be found on the Maven Local Settings Model Website.
设置的描述符文档可以在Maven Local Settings Model网站上找到。
http://maven.apache.org/ref/3.6.3/maven-settings/settings.html
Note: The official Maven repository is at https://repo.maven.apache.org/maven2
hosted by the Sonatype Company and is distributed worldwide via CDN.
注意:官方Maven仓库在Sonatype 公司的https://repo.maven.apache.org/maven2
,并通过CDN向全世界分发。
A list of known mirrors is available in the Repository Metadata
. These mirrors may not have the same contents and we don’t support them in any way.
已知的镜像列表可在Repository Metadata
中找到,这些镜像的内容可能会不一样,我们不以任何方式对它们提供支持。
https://repo.maven.apache.org/maven2/.meta/repository-metadata.xml
使用单仓库-Using A Single Repository
You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories. This setting is most useful when using an internal company repository with a Maven Repository Manager to proxy external requests.
你可以强制Mave使用单个仓库,这个仓库镜像回应所有的仓库请求。该仓库必须包含所有需要的artifacts, ,或者能够将请求代理到其他仓库。这一设置在下面这种情况下是很有用的:当使用公司内部的仓库,借由Maven Repository Manager来代理external请求。
http://maven.apache.org/repository-management.html
desired
美[dɪ'zaɪrd]英[dɪ'zaɪə(r)d]
v.“desire”的过去分词和过去式
网络渴望的;期望的;想得到的
To achieve this, set mirrorOf
to *
.
要达到这个目的,将 mirrorOf
设置为 *
.
Note: This feature is only available in Maven 2.0.5+.
注意: 这个特性只在 2.0.5+才支持。
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
【例子】
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
镜像的高级参数-Advanced Mirror Specification
specification
美[.spesɪfɪ'keɪʃ(ə)n]英[.spesɪfɪ'keɪʃ(ə)n]
n.规范;规格;明细单;说明书
网络产品规格;规格说明;技术参数
A single mirror can handle multiple repositories when used in conjunction with a repository manager.
单个镜像与一个repository manager
一起使用时,可以handle 多个仓库。
The syntax as of Maven 2.0.9:
这是Maven 2.0.9的语法。
-
*
matches all repo ids. -
* 匹配所有仓库
external:*
matches all repositories except those using localhost or file based repositories. This is used in conjunction with a repository manager when you want to exclude redirecting repositories that are defined for Integration Testing.external:*
匹配所有的仓库,除了使用localhost或 file based的仓库。当你想排除那些,因为集成测试而被重定向的仓库时,和repository manager一起使用。
conjunction
美[kən'dʒʌŋkʃ(ə)n]英[kən'dʒʌŋkʃ(ə)n]
n.连词;同时发生;(恒星、行星等的)合
网络连接词;结合;联合
integration
美[ˌɪntəˈɡreɪʃ(ə)n]英[ˌɪntɪˈɡreɪʃ(ə)n]
n.一体化;结合;融入群体或社会;【政】取消种族隔离
网络整合;集成;综合
- multiple repositories may be specified using a comma as the delimiter
-
多个仓库间可以指定使用逗号作为分隔符。
- an exclamation mark may be used in conjunction with one of the above wildcards to exclude a repository id
- 感叹号
!
可以选择上述通配符中的一个
配合使用,用来排除仓库ID。
exclamation
美[.eksklə'meɪʃ(ə)n]英[.eksklə'meɪʃ(ə)n]
n.感叹;感叹词;感叹语
网络惊叹号;惊叹词;惊呼
Be careful not to include extra whitespace around identifiers or wildcards in comma separated lists. For example, a mirror with <mirrorOf
> set to !repo1, *
will not mirror anything while !repo1,*
will mirror everything but repo1
.
注意不要在逗号分隔的列表中的标识符或通配符周围加入额外的空格。 例如,将 <mirrorOf>
设为 !repo1, *
的镜像不会镜像任何东西(因为有空格),但如果设置为 !repo1,*
将会镜像到除 repo1
外的仓库。
identifier
美[aɪ'dentɪ'faɪəz]英[aɪ'dentɪ'faɪəz]
n.标识符;鉴定人;识别符号;标志符号
网络识别字;标示符;标识词
变形复数:identifiers;
wildcard
n.通配符
网络外卡;字元;万用字元
The position of wildcards within a comma separated list of repository identifiers is not important as the wildcards defer to further processing and explicit includes or excludes stop the processing, overruling any wildcard match.
通配符在逗号分隔的仓库标识符列表中的位置并不重要,因为通配符会推迟到进一步的处理,而显式的包含或排除则会停止处理,覆盖任何通配符匹配。
defer
美[dɪ'fɜr]英[dɪ'fɜː(r)]
v.推迟;延缓;展期
网络延期;拖延;延迟
变形第三人称单数:defers;现在分词:deferring;过去式:deferred;
further
美['fɜrðər]英['fɜː(r)ðə(r)]
adv.进一步;此外;更远;而且
v.促进;增进
adj.更多的;更进一步的;附加的
explicit
美[ɪk'splɪsɪt]英[ɪk'splɪsɪt]
adj.清楚明白的;易于理解的;明确的;直言的
网络显式;清楚的;显性
When you use the advanced syntax and configure multiple mirrors, keep in mind that their declaration order matters. When Maven looks for a mirror of some repository, it first checks for a mirror whose <mirrorOf>
exactly matches the repository identifier. If no direct match is found, Maven picks the first mirror declaration that matches according to the rules above (if any). Hence, you may influence match order by changing the order of the definitions in the settings.xml
当你使用高级语法并配置多个镜像时,它们的声明顺序很重要。当Maven寻找某个仓库的镜像时,它首先会检查其<mirrorOf>
与仓库标识符完全匹配的镜像(mirror)。 如果没有找到直接匹配的镜像,Maven会根据上述规则(如果有的话)选择第一个匹配的镜像声明。因此,你可以通过改变settings.xml
中定义的顺序来影响匹配顺序。
exactly
美 [ɪɡ'zæk(t)li]
英 [ɪɡ'zæk(t)li]
adv.到底;确切地;准确地;精确地
网络正是;完全正确;恰恰
hence
美 [hens]
英 [hens]
adv.因此;由此
int.〈诗〉去
网络所以;从此;今后
influence
美 ['ɪnfluəns]
英 ['ɪnfluəns]
n.影响;作用;影响力;支配力
v.影响;左右;对…起作用;支配
网络感化;势力;影响型
Examples:
*
= everything-
*
= 匹配所有 external:*
= everything not on the localhost and not file based.-
external:*
= 不在本地和不是基于文件的一切 -
repo,repo1
= repo or repo1 *,!repo1
= everything except repo1*,!repo1
= 排除repo1的所有
Note: This feature is only available in Maven 2.0.9+.
注意:此功能仅在Maven 2.0.9+可用。
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>external:*,!foo</mirrorOf>
</mirror>
<mirror>
<id>foo-repository</id>
<name>Foo</name>
<url>http://repo.mycompany.com/foo</url>
<mirrorOf>foo</mirrorOf>
</mirror>
</mirrors>
...
</settings>
创建你自己的镜像-Creating Your Own Mirror
The size of the central repository is increasing steadily To save us bandwidth and you time, mirroring the entire central repository is not allowed. (Doing so will get you automatically banned) Instead, we suggest you setup a repository manager
as a proxy.
central仓库的规模正在稳步增长。为了节省我们的带宽和您的时间,不允许镜像整个中央仓库。(这样做会让您自动被禁止)。相反,我们建议您设置repository manager
作为代理。
steadily
美
英 ['stedɪlɪ]
adv.稳定地;坚定地;坚固地;不断地
网络稳固地;平稳地;稳步地
bandwidth
美 ['bænd.wɪdθ]
英 ['bænd.wɪdθ]
n.带宽;频宽;带宽值
网络设置接口的带宽;频带宽度;宽带
http://maven.apache.org/repository-management.html
If you really want to become an official mirror, contact us at MVNCENTRAL
with your location and we’ll work to get you setup.
如果你想成为官方的镜像,请在MVNCENTRAL
联系我们,告诉我们你的位置,我们会努力帮你设置。
https://issues.sonatype.org/browse/MVNCENTRAL
附加
阿里的镜像:
https://maven.aliyun.com/mvn/guide
<settings>
...
<mirrors>
<mirror>
<id>aliyun-central-mirror</id>
<name>阿里云central</name>
<url>https://maven.aliyun.com/repository/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
...
</settings>
central仓和jcenter仓的聚合仓:
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
163镜像:
http://mirrors.163.com/.help/maven.html
<mirror>
<id>nexus-163</id>
<mirrorOf>*</mirrorOf>
<name>Nexus 163</name>
<url>http://mirrors.163.com/maven/repository/maven-public/</url>
</mirror>