文档章节

mave 配置文件里面的setting 配置仓库

Oscarfff
 Oscarfff
发布于 2016/02/08 12:14
字数 819
阅读 105
收藏 0

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.

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

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 US repository included by default is central, so to use the European Central instance, you would configure the following:

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

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.

The settings descriptor documentation can be found on the Maven Local Settings Model Website.

Note: The official Maven 2 repository is at http://repo.maven.apache.org/maven2 hosted in the US, or http://uk.maven.org/maven2 hosted in the UK.

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.

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 the Maven Repository Manager to proxy external requests.

To achieve this, set mirrorOf to *.

Note: This feature is only available in Maven 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>

Advanced Mirror Specification

A single mirror can handle multiple repositories when used in conjunction with a repository manager.

The syntax as of 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.

  • 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

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.

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

Examples:

  • * = everything

  • external:* = everything not on the localhost and not file based.

  • repo,repo1 = repo or repo1

  • *,!repo1 = everything except repo1

Note: This feature is only available in 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.

If you really want to become an official mirror, contact us at MVNCENTRAL with your location and we'll work to get you setup.


本文转载自:https://maven.apache.org/guides/mini/guide-mirror-settings.html

共有 人打赏支持
Oscarfff
粉丝 72
博文 815
码字总数 96913
作品 0
崇明
后端工程师
如何在maven项目中正确引用自己打包的jar

1、通过mvn clean install,将项目的jar安装到了maven的本地仓库。 HelloWorld-0.0.1-SNAPSHOT.pom的内容如下:

霍艳超
2015/04/16
22.2K
5
【Maven】项目管理利器Maven(三)——本地仓库、远程仓库(私服)和中央仓库

一、前言 在上一篇博客中,小编向大家介绍了如何安装和配置Maven,当然啦,我们配置好Maven后,就要看看它的配置文件了,配置文件中,就不得不提提文件里面配置的内容有什么了,在这篇博客中...

kisscatforever
01/15
0
0
Maven的使用,Nexus建立本地仓库以及Eclipse导入Maven项目(四): 实战篇

Maven的使用,Nexus建立本地仓库以及Eclipse导入Maven项目(四): 实战篇 项目实战篇: ================================================================ 下载项目 ------------------------......

DavyZhong
2012/11/12
0
4
maven:mirrors和repository的关系区别

原文地址:http://my.oschina.NET/sunchp/blog/100634 1 Repository(仓库) 1.1 Maven仓库主要有2种: remote repository:相当于公共的仓库,大家都能访问到,一般可以用URL的形式访问 lo...

ke_ry
2017/09/04
0
0
maven几种常见错误的解决方法

一、must override a superclass method 错误 首先我们得知道: @override注释在jdk1.5环境下只能用于对继承的类的方法的重写,而不能用于对实现的接口中的方法的实现,在jdk1.6环境下对于继...

cjun1990
2015/01/14
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

获取多个集合列表的笛卡尔积

获取多个集合笛卡尔积 电商中典型业务场景:商品搜索 单属性属性值之间为并查询 不同属性的属性值之间查询为与查询 import java.util.ArrayList;import java.util.List;/** * Created w...

键走偏锋
23分钟前
0
0
echarts 迁移地图 控制鼠标缩放大小比例

在网上找了好久没有找到解决方式,还是重新看了一下文档,终于找到的解决方案, zoom:1, //默认显示级别 scaleLimit:{min:1,max:3}, // 缩放级别 echarts 文档-配置项链接 http://echarts.b...

心驰
26分钟前
0
0
Boot2Docker ISO is out-of-date,

Boot2Docker ISO is out-of-date, downloading the latest release. 使用docker-machine时无法更新Boot2Docker ISO导致创建vm machine失败 解决方法:关闭网络,创建好之后再开启...

writeademo
34分钟前
0
0
在 Tomcat 中设置 Tapestry 框架的 html 热加载

如果开发中使用到了 Tapestry 这个框架,如果事先没有设置过的话,开发的时候 html 是不会热加载的,也就是说修改了 html 文件,不能刷新浏览器后立马看到修改完的效果,必须先重新启动应用服...

LeoXu
56分钟前
0
0
【微服务】开启巨石应用到微服务的探索

背景 在过去的一年时间里,我一直在从事一件事情,将现有的单体应用(巨石应用)向微服务改造。 接下来,将持续整理一些在微服务路上的学习与成长。 为什么要做微服务 单体应用,开发、部署简...

艳沐石
今天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部