在实际项目中会存在多个仓库,包括我们自建的Nexus私有仓库和阿里仓,这里就需要设置多仓的顺序,防止jar包不在其中一个仓库时会自动从另外一个仓库中拉取。
  Maven的Setting配置中有mirror和repository,它们的作用都是配置远程maven仓库的地址。repository就是直接配置站点地址,mirror则是作为站点的镜像,代理某个或某几个站点的请求,实现对repository的完全代替。
   
  有两种形式可以配置多个repository, 配置多个profile或者在同一个profile中配置多个repository.配置多profile时,还需要配置activeProfiles使配置生效。
  下载依赖时,maven会按照配置从上到下的顺序,依次尝试从各个地址下载,成功下载为止。
  无论是配置国内的maven仓库,还是配置nexus之类私服,都可以直接配置成repository, 这样即使配置的这些仓库有些问题导致一些包下不下来,也可以继续用别的仓库尝试。
 
  <repository>时<id>似乎也没什么用,如果你只是在pom.xml中配置个仓库,这个id是没什么用的,可以随便写。这个id是配合上面讲的mirror一块使用的,还记得mirrorOf吗,我们配置mirrorOf为<mirrorOf>central</mirrorOf>是,mirror中的url会将默认的central仓库的url给覆盖了,所以这里的<repository>标签下的id是给mirrorOf用的。当repository中的id与mirrorOf一致时,mirrorOf中的url就会覆盖repository中的url地址。
 
  在Mirrors部分可以配置多个镜像仓库,但是在该部分配置多个仓库,并不能提供自动查询多个仓库的功能,默认还是取第一个仓库进行查询。
  我们这里采用设置profiles的方式来达到想要的目的,直接上配置:
<?xml version="1.0" encoding="utf-8"?>
<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>D:/m2/repository</localRepository>
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>nexus-releases</id>
<username>ali</username>
<password>123456</password>
</server>
</servers>
<mirrors>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>nexus-releases</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://10.3.87.5:8082/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>aliyun</activeProfile>
<activeProfile>nexus-releases</activeProfile>
</activeProfiles>
</settings>

注意:这里面配置了maven.compiler.source,当环境中有jdk1.8以下版本时用maven打包时会报jdk低版本的提示,需要统一打包时jdk的版本,因此需要在此指定

多个仓库源配置及repositories和mirrors的配置的更多相关文章

  1. Linux Yum仓库源配置

    Yum概念:Yum软件仓库的作用是为了进一步简化RPM管理软件的难度以及自动分析所需软件包及其依赖关系的技术 Yum配置仓库源放置位置:/etc/yum.repo.d/ :配置文件需以 .repo 结 ...

  2. 使用apt-mirror建立本地debian仓库源

    先介绍一下环境: 主机:Win7 虚拟机:VirtualBox + Debian7 由于软件源的体积比较大,所以我又给虚拟机添加了一块50GB的虚拟硬盘(给虚拟机添加虚拟硬盘的方法参见:http:// ...

  3. Linux centosVMware yum更换国内仓库源、yum下载rpm包、源码包安装

    一.yum更换国内仓库源 cd /etc/yum.repos.d/ rm -f dvd.repo wget http://mirrors.163.com/.help/CentOS7-Base-163. ...

  4. yum仓库源搭建

    本地yum源搭建 cd源 mount /dev/sr0 /mnt vim  /etc/yum.repos.d/base.repo [centos-base]name=centos7#baseurl=f ...

  5. npm设置和查看仓库源

    转载请注明出处:https://www.cnblogs.com/wenjunwei/p/10078460.html 在使用npm命令时,如果直接从国外的仓库下载依赖,下载速度很慢,甚至会下载不下来,我 ...

  6. Atitit 项目源码的架构,框架,配置与环境说明模板 规范 标准化

    Atitit 项目源码的架构,框架,配置与环境说明模板  规范 标准化 版本1.0 作者 艾龙 attilax 1. 概述:核心业务: 1 1.1. 功能文档路径 /palmWin/src/docum ...

  7. git 修改远程仓库源

    自己已经写好了一个项目,想上传到 github github 创建新项目 新建 README.md , LICENSE 本地项目添加 github 远程仓库源 不是git项目 git remote a ...

  8. 源码学习系列之SpringBoot自动配置(篇一)

    源码学习系列之SpringBoot自动配置源码学习(篇一) ok,本博客尝试跟一下Springboot的自动配置源码,做一下笔记记录,自动配置是Springboot的一个很关键的特性,也容易被忽略的属 ...

  9. 源码学习系列之SpringBoot自动配置(篇二)

    源码学习系列之SpringBoot自动配置(篇二)之HttpEncodingAutoConfiguration 源码分析 继上一篇博客源码学习系列之SpringBoot自动配置(篇一)之后,本博客继续 ...

  10. SpringBoot源码学习系列之SpringMVC自动配置

    目录 1.ContentNegotiatingViewResolver 2.静态资源 3.自动注册 Converter, GenericConverter, and Formatter beans. ...

随机推荐

  1. SPPS完整版下载安装教程【博主亲测】

    SPSS全称Statistical Product and Service Solutions,是一款优秀的数据分析软件,旨在为用户提供专业的统计产品与服务解决方案.SPSS面向行业应用人员所设,被广 ...

  2. python基础(三)装饰器

    字典推导式: data_list = ['1 hello','2 world'] result = {item.split(" ")[0]: item.split(" & ...

  3. php 高并发

    1 swoole的博客 http://rango.swoole.com/archives/508 2 消息队列 3 接口并发请求

  4. 【DL论文精读笔记】Object Detection in 20 Y ears: A Survey目标检测综述

    目标检测20年综述(2019) 摘要 Abstract 该综述涵盖了400篇目标检测文章,时间跨度将近四分之一世纪.包括目标检测历史上的里程碑检测器.数据集.衡量指标.基本搭建模块.加速技术,最近的s ...

  5. Spring Boot实现任意位置的properties及yml文件内容配置与获取

    〇.参考资料 1.Spring Boot 中文乱码问题解决方案汇总 https://blog.51cto.com/u_15236724/5372824 2.spring boot读取自定义配置prop ...

  6. C++四舍五入并且保留7为小数

    问题描述给定圆的半径r,求圆的面积.输入格式输入包含一个整数r,表示圆的半径.输出格式输出一行,包含一个实数,四舍五入保留小数点后7位,表示圆的面积.说明:在本题中,输入是一个整数,但是输出是一个实数 ...

  7. intel Pin:动态二进制插桩的安装和使用,以及如何开发一个自己的Pintool

    先贴几个你可能用得上的链接 intel Pin的官方介绍Pin: Pin 3.21 User Guide (intel.com) intel Pin的API文档Pin: API Reference ( ...

  8. ATM购物车项目总结

    目录 项目实现思路 ATM项目 优先实现功能 拆分函数 项目路径展示 项目启动文件 start.py 配置文件 setting.py 日志配置字典 日志函数 展示层 src.py 用户注册 获取用户输 ...

  9. 《HTTP权威指南》– 10.安全HTTP

    HTTPS的概念 HTTPS 是最流行的HTTP安全模式,由网景公司首创,所有主流浏览器和服务器都支持此协议.HTTPS方案 的URL以 https:// 开头,使用 HTTPS 时,所有的HTTP请 ...

  10. python -m pip install --upgrade pip报No module named pip解决方法

    解决方法: 1. python -m ensurepip 2. python -m pip install --upgrade pip 注意:添加pip环境变量 在python安装目录下搜索pip3或 ...