• 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
    如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的

  • 相关阅读:
    计算机网络中协议相关的问题(转)
    Vs2013打开项目时,一直处理等待状态,并显示“Microsoft Visual Studio正忙”的提示窗,处理方法(转)
    ASP.NET Core 2.2 十九. Action参数的映射与模型绑定(转)
    ASP.NET Core 2.2 十八.各种Filter的内部处理机制及执行顺序(转)
    ASP.NET Core 2.2 : 十七.Action的执行(Endpoint.RequestDelegate后面的故事)(转)
    ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案(转)
    【Leetcode】771. Jewels and Stones
    【Leetcode】50. Pow(x, n)
    【Leetcode】 328. Odd Even Linked List
    【leetcode】59.Spiral Matrix II
  • 原文地址:https://www.cnblogs.com/my_captain/p/12245511.html
Copyright © 2020-2023  润新知