Maven配置文件中 mirror和repository的区别及中央仓库配置大全

Stella981
• 阅读 2311

1、Maven配置文件中 mirror和repository的区别

1.1 repository

repository就是个仓库,maven里有两种仓库,Local Repository(本地仓库)和Remote Repository(远程仓库)。
Maven配置文件中 mirror和repository的区别及中央仓库配置大全

1.1.1 Remote Repository(远程仓库)主要有3种
  • 中央仓库:http://repo1.maven.org/maven2/
  • 私服:内网自建的maven repository,其URL是一个内部网址
  • 其他公共仓库:其他可以互联网公共访问maven repository,例如 jboss repository等。
1.1.2 本地和远程的区别
  • 远程仓库相当于公共的仓库,大家都能看到。

  • 本地仓库是你本地的缓存副本,只有你看的到,主要起缓存作用。

  • 当你向仓库请求插件或依赖的时候,会先检查本地仓库里是否有。 如果有则直接返回,否则会向远程仓库请求,并被缓存到本地仓库。

  • 远程仓库可以在工程的pom.xml文件里指定。 如果没指定,默认会到http://repo1.maven.org/maven2 这个地方去请求插件和依赖包

    <repository>  
          <snapshots>  
              <enabled>false</enabled>  
          </snapshots>  
          <id>central</id>  
          <name>Maven Repository Switchboard</name>  
          <url>http://repo1.maven.org/maven2</url>  
    </repository>
    

本地仓库默认在你本地的用户目录下的.m2/repository目录下

1.2 mirror

mirror相当于一个拦截器,它会拦截maven对remote repository的相关请求,把请求里的remote repository地址,重定向到mirror里配置的地址。
mirror就是镜像,主要提供一个方便地切换远程仓库地址的途径。例如,上班的时候在公司,用电信的网络,连的是电信的仓库。回到家后,是网通的网络,我想连网通的仓库,就可以通过mirror配置,统一把我工程里的仓库地址都改成联通的,而不用到具体工程配置文件里一个一个地改地址。
mirror的配置在.m2/settings.xml里。如:

<mirrors>  
  <mirror>  
    <id>UK</id>  
    <name>UK Central</name>  
    <url>http://uk.maven.org/maven2</url>  
    <mirrorOf>central</mirrorOf>  
  </mirror>  
</mirrors> 

这样的话,就会给上面id为central的远程仓库做了个镜像。以后向central这个仓库发的请求都会发到 http://uk.maven.org/maven2 而不是 http://repo1.maven.org/maven2 了。 central里是要替代的仓库的id。如果填*,就会替代所有仓库。

1.3 高级镜像配置
  1. *
    匹配所有远程仓库。
  2. external:*
    匹配所有远程仓库,使用localhost的除外,使用file:// 协议的除外。也就是说,匹配所有不在本机上的远程仓库。
  3. repo1,repo2
    匹配仓库repo1和repo2,使用逗号分隔多个远程仓库。
  4. *,!repo1
    匹配所有远程仓库,repo1除外,使用感叹号将仓库从匹配中排除。

2、maven中央仓库集

可以自行转化为mirror

1、阿里中央仓库
<repository>  
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository> 
2.camunda.com 中央仓库
<repository>  
    <id>activiti-repos2</id>  
    <name>Activiti Repository 2</name>  
    <url>https://app.camunda.com/nexus/content/groups/public</url>  
</repository>  
3.alfresco.com 中央仓库
<repository>  
    <id>activiti-repos</id>  
    <name>Activiti Repository</name>  
    <url>https://maven.alfresco.com/nexus/content/groups/public</url>  
</repository>  
4.spring.io 中央仓库
<repository>  
    <id>springsource-repos</id>  
    <name>SpringSource Repository</name>  
    <url>http://repo.spring.io/release/</url>  
</repository>
5.maven.apache.org 中央仓库
<repository>  
    <id>central-repos</id>  
    <name>Central Repository</name>  
    <url>http://repo.maven.apache.org/maven2</url>  
</repository>
6.maven.org 中央仓库
<repository>  
    <id>central-repos1</id>  
    <name>Central Repository 2</name>  
    <url>http://repo1.maven.org/maven2/</url>  
</repository>
7.oschina 中央仓库
<repository>  
    <id>oschina-repos</id>  
    <name>Oschina Releases</name>  
    <url>http://maven.oschina.net/content/groups/public</url>  
</repository>  
8.oschina thinkgem 中央仓库
<repository>   
    <id>thinkgem-repos</id>   
    <name>ThinkGem Repository</name>  
    <url>http://git.oschina.net/thinkgem/repos/raw/master</url>  
</repository> 
9.java.net 中央仓库
<repository>  
    <id>java-repos</id>  
    <name>Java Repository</name>  
    <url>http://download.java.net/maven/2/</url>  
</repository>
10.github.com 中央仓库
<repository>   
    <id>thinkgem-repos2</id>   
    <name>ThinkGem Repository 2</name>  
    <url>https://raw.github.com/thinkgem/repository/master</url>  
</repository>  

前六个可以正常使用,后四个如若要使用可能需要一些神奇的操作,在这偶就不说了...


参考:


欢迎关注我的公众号【穿着条纹睡衣的男孩】,因为才注册,所以需要大家的大力支持啊!!! 关注后可领取java和c++的学习资源视频,作为礼物!!!
Maven配置文件中 mirror和repository的区别及中央仓库配置大全
Maven配置文件中 mirror和repository的区别及中央仓库配置大全

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Stella981 Stella981
2年前
Gradle + GitHub Actions 自动发布项目至 Maven 仓库
摘要文章内容核心是使用Gradle整合GitHubActions自动化发布Java项目至Maven仓库。文章内是将项目发布至sonatype提供的仓库中。如果你需要自动化发布,或者需要将项目同步至Maven中央仓库请仔细阅读。前期准备1.可同步Maven中央仓库的门票,在IssuesSona
Stella981 Stella981
2年前
Maven 国内镜像(Maven下载慢的解决方法)
  Maven是当前流行的项目管理工具,但官方的库在国外经常连不上,连上也下载速度很慢。国内oschina的maven服务器很早之前就关了。今天发现阿里云的一个中央仓库,亲测可用。1<mirror2<idalimaven</id3<mirrorOfcentral</mirrorOf4
Stella981 Stella981
2年前
Maven使用 国内镜像配置
Maven使用国内镜像配置  Maven  setting.xml中配置<repositories<repository<idnexus</id<namelocalprivatenexus</name
Stella981 Stella981
2年前
Idea下maven的配置和使用
  maven的主要功能就是依赖管理,jar包仓库。和C中的NuGet仓库差不多。另外也提供打包构建,启动插件等功能。下面主要讲一下,在使用Idea开发时,maven的配置和使用。maven的安装和配置  maven(3.6.1)的下载地址:https://idlestudio.ctfile.com/fs/14960372382
Stella981 Stella981
2年前
Maven镜像源
Maven仓库镜像修改Mavensetting.xml文件在<mirrors标签内添加以下镜像。<fontcolor"red"注意:如果构建错误,请根据错误信息,调整镜像位置</font<mirror<idrepo2</id<mirrorOfcentral</m
Stella981 Stella981
2年前
Docker搭建私有镜像仓库
docker仓库的工作原理和maven的类似,他们都提供了提供了一个中央仓库,允许用户科技直接从中央仓库下载,同时我们也可以搭建自己的本地私有仓库。docker本地私有镜像仓库的优点:1.从私有仓库中下载节省网络带宽;2.从私有仓库中下载速度快,一般都是局域网络内部署;3.托管不对外的内部镜像;下面我们将完整的说明使用docker
Stella981 Stella981
2年前
Intellij IDEA配置Maven(内置Maven和修改本地仓库地址和阿里云中央仓库)
一.更改说明1.IntellijIDEA是有自己的Maven插件的,我们只需要配置一下就可以2.默认仓库位置为C:\\Users\\账户.m2\\repository,如果不更改仓库就会占用C盘空间,反正我的使用没多久仓库就是几个G大小了。二.配置说明1.FileSettings(Setting
Stella981 Stella981
2年前
Maven仓库
maven仓库分为本地仓库、远程仓库。项目引用依赖时,先从本地仓库按照坐标查找,如果没有找到则到远程仓库查找,如果还没有就报错。设定本地仓库修改setting.xml文件配置,自定义本地仓库路径。本地仓库只有一个。<localRepository/path/to/local/repo</localRepository
Stella981 Stella981
2年前
Maven仓库介绍
何为仓库Maven中的仓库用来存放生成的构建和各种依赖。严格说来只有两种仓库:本地和远程。本地仓库指本机的一份拷贝,用来缓存远程下载、包含你尚未发布的临时构件。远程仓库指通过各种协议如file://和http://访问的其它类型的仓库。这些仓库可能是第三方搭建的真实的远程仓库,用来提供他们的构件下载(例如repo.mave