配置Maven从Nexus下载构件 
当需要为项目添加Nexus私服上的public仓库时,配置如下:

<project>
    ...
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://localhost:8081/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://localhost:8081/nexus/context/groups/public/</url>
            <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
    </pluginRepositories>
    ...
</project>

这样的配置只对当前Maven项目有效,在实际应用中,我们往往想要通过一次配置就能让本机所有的Maven项目都使用自己的Maven私服。 
这个时候我们想到settings.xml文件,该文件中的配置对所有本机Maven项目有效,但是settings.xml并不支持直接配置repositories和pluginsRepositories。所幸Maven还提供了Profile机制,能让用户将仓库配置放到settings.xml的profile中,代码如下:

<settings>
    ...
    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <id>nexus</id>
                <name>Nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public/</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></releases>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>Nexus</name>
                    <url>http://localhost:8081/nexus/content/groups/public/</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></releases>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
    ...
</settings>

该配置中使用了一个id为nexus的profile,这个profile包含了相关的仓库配置,同时配置中又使用了activeProfile元素将nexus这个profile激活。这样当执行Maven构建的时候,激活的profile会将仓库配置应用到项目中去。Maven除了从Nexus下载构件之外,还会访问中央仓库central,我们希望的是所有Maven下载请求都仅仅通过Nexus,以全面发挥私服的作用。这需要借助Maven镜像配置了。可以创建一个匹配任何仓库的镜像,镜像地址为私服,这样Maven对任何仓库的构件下载请求都会转到私服中,具体配置如下:

<settings>
    ...
    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://localhost:8081/nexus/content/groups/public</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></releases>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
    ...
</settings>

这里需要解释的是仓库插件及插件仓库配置,他们id都为central,覆盖了超级POM中的中央仓库配置,他们的url已无关紧要��因为所有的请求都会通过镜像访问私服地址。配置仓库及插件仓库的主要目的是开启对快照版本下载的支持。当Maven需要下载发布版本或者快照构件时,首先检查central,看该类型构件是否支持下载,得到正面回答后再根据镜像匹配规则转而访问私服仓库地址。

配置Maven从Nexus下载构件相关推荐

  1. 配置Maven从私服下载构件

    --------------------siwuxie095 配置 Maven 从私服下载构件 从 Nexus 私服下载构件的配置方法共有三种 1.法一: 在 pom.xml 的 project 标签 ...

  2. 配置maven私服nexus

    1.Nexus简介 1.1 Nexus概述 Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问. 利用Nexus你可以只在一个地方就能够完全控制访问和部署在你 ...

  3. 配置Maven使用Nexus

    有两种方式 第一种:最简单明了的方式 直接在你项目的pom.xml中添加如下 <repositories> <repository> <snapshots> < ...

  4. nexus(maven仓库)搭建配置maven本地私有仓库

    一 私服的作用,为什么要使用私服? 内网访问,内网团队使用一个服务缓存节省外网宽带. 微服务开发中加速 Maven 项目构建,加快团队合作,提高工作效率 允许上传和下载私有库,并且不被外部访问,安全 ...

  5. maven私服nexus搭建(windows)

    1.下载nexus 地址:https://www.sonatype.com/download-oss-sonatype 下载相应版本的zip包. 2.安装nexus 下载完成后,解压到本地任意目录. ...

  6. Jenkins CI服务器搭建及Maven私服Nexus

    Jenkins CI服务器搭建及Maven私服Nexus 一:Jenkins持续集成(CI)1 1.1:Jenkins简介及特性1 1.2:Jenkins安装1 1.3:Jenkins配置1 1.4: ...

  7. IntellIJ IDEA 配置 Maven 以及 修改 默认 Repository

    今天将IntellIJ IDEA 关于Maven的配置总结一下,方便以后可参考. IDEA版本: IntelliJ IDEA 2017.2 Build #IU-172.3317.76, built o ...

  8. IntellIJ IDEA 配置 Maven 以及 修改 默认 Repository

    今天将IntellIJ IDEA 关于Maven的配置总结一下,方便以后可参考. IDEA版本: IntelliJ IDEA 2017.2 Build #IU-172.3317.76, built o ...

  9. Maven与nexus

    开始在使用Maven时,总是会听到nexus这个词,一会儿maven,一会儿nexus,当时很是困惑,nexus是什么呢,为什么它总是和maven一起被提到呢? 我们一步一步来了解吧. 一.了解Mav ...

最新文章

  1. Java学生宿舍管理系统,即将毕业的兄弟有福了!
  2. 如何将全景分割用到养猪场?
  3. android8.0和9.0平板电脑区别,安卓9.0和8.0有什么区别? 哪个更好
  4. MTK 驱动(85)----RPMB key introduction
  5. python获取post请求中的所有参数_Django从POST reques获取请求参数
  6. fir.im Weekly - 技术人也要苦练“七十二变”
  7. DPDK QOS2 -- DPDK的QOS框架
  8. Spring4新特性——泛型限定式依赖注入
  9. vm14安装mac10教程(亲测;转载)
  10. 图像的稀疏表示(Sparse Representation)
  11. 调用webservice服务方式总结
  12. Facebook的原罪与区块链的救赎
  13. 计算机网络 | 应用层
  14. 基于VUE使用Hbuilder工具开发的思维导图工具
  15. 服务器开机必须要按f1才能进系统,为什么开机要按f1才能进系统
  16. R语言—90分钟从入门到精通
  17. 图卷积(1)——从欧式空间到非欧式空间
  18. NirCmd-v2.52使用说明中文译本
  19. David P.Williams论文系列 合成孔径声纳图像快速目标检测:一种新算法及大规模性能分析
  20. 【JS】820- JS 常见报错及异常捕获

热门文章

  1. not support mysql_MYSQL(解决方法):Client does not support authentication
  2. GCC源码分析(十四) — rtx结构体,指令与栈分配
  3. vs2019添加DevExpress
  4. python语言程序设计实践教程答案上海交通大学陈东_《C语言程序设计》蔺德军 主著【摘要 书评 在线阅读】-苏宁易购图书...
  5. 细说二维码扫码登录的原理
  6. Hive项目之谷粒影音:ETL清洗原数据、Hive统计视频观看数top10、视频类别top、视频观看数top其所属类别、类别流量top、类别热度top、上传视频用户数量top、类别视频观看top
  7. 算法竞赛从入门到进阶pdf_ACMICPC/CCPC算法竞赛入门建议
  8. win10 字体渲染优化 色彩调整
  9. jsp项目使用jstl(c标签)及jstl.jar和standard.jar
  10. python3连接oracle教程,python3连接oracle数据库