zoukankan      html  css  js  c++  java
  • maven入门基础:配置maven从nexus下载构件(十四)

    一. 单个pom.xml形式:适合单个项目

    <repositories>
            <repository>
                <id>nexus</id>
                <name>Nexus</name>
                <url>http://192.168.0.105:8086/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>
                <!-- 这个地址是私服groups类型的地址,该地址从私服仓库列表的最后一列可查看 -->
                <url>http://192.168.0.105:8086/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>

    注意:setting.xml中不能不能写成这样<mirrorOf>*</mirrorOf>,否则所有的构件都会从阿里云上下载,我们的pom.xml配置的私服就无效了。可以写成<mirrorOf>central</mirrorOf>,只有中央仓库的构件从阿里云上下载,其他从私服上下载

    <mirrors>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
      </mirrors>

    可以看到,maven正在从私服上下载构件

    完成后查看,本地仓库和私服仓库

    二. setting.xml方式:适合所有项目

    1. 定义私服仓库

    <!-- 定义私服仓库 -->
    </profiles>
        <profile>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <name>Nexus</name>
                    <url>http://192.168.0.105:8086/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://192.168.0.105:8086/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                 </pluginRepository>
            </pluginRepositories>
        </profile>
      </profiles>
      <!-- 激活私服 -->
      <activeProfiles>
        <activeProfile>nexus</activeProfile>
      </activeProfiles>

    2. 所有请求转向私服

    <mirrors>
        <mirror>
            <id>nexus</id>
            <name>Nexus</name>
            <!-- http://maven.aliyun.com/nexus/content/groups/public/ -->
                    <url>http://192.168.0.105:8086/nexus/content/groups/public/</url>
            <mirrorOf>*</mirrorOf>
        </mirror>
    </mirrors>

    对应私服服务器下的/nexus/storage/目录

    三. 配置优先级

    settings.xml文件一般存在于两个位置:

    • 全局配置: ${M2_HOME}/conf/settings.xml
    • 用户配置: user.home/.m2/settings.xml
    • (note:用户配置优先于全局配置。)

    需要注意的是:局部配置优先于全局配置
    配置优先级从高到低:pom.xml> user settings > global settings
    如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的

  • 相关阅读:
    [开荒啦]ECS服务器初体验
    [邻接矩阵形式]无向图的建立与深度,广度遍历
    [Java 学习笔记] 泛型
    2021辽宁省大学生程序设计竞赛 C D E F G I L
    [DOJ 练习] (取余优化) 判断一个字符串不区分大小写是否回文
    [Acwing Linux基础课] Docker基本操作
    [图解] 数组模拟Trie树
    http://bbs.windows7en.com/thread3102611.html win7
    简单介绍Linux下安装Tomcat的步骤
    linux下导入导出MySQL数据库
  • 原文地址:https://www.cnblogs.com/my_captain/p/12245511.html
Copyright © 2011-2022 走看看