Maven配置多个仓库地址

小柒博客 Maven评论8661字数 1581阅读5分16秒阅读模式

在Maven的settings.xml文件中配置多个仓库,其中基础依赖使用阿里云仓库,其他依赖使用Nexus仓库,可以按照以下步骤进行操作:

第一种方式:

[root@localhost ~]# vim /usr/local/maven/conf/settings.xml

1、在<mirrors>标签中添加如下配置

<mirrors>
    <mirror>
        <id>aliyun</id>
        <name>Aliyun Mirror</name>
        <url>https://maven.aliyun.com/repository/public</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

2、在<profiles>标签内,创建一个新的profile,并添加如下配置

<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>https://your-nexus-repo-url</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</profile>

注意:把https://your-nexus-repo-url替换为实际的Nexus仓库URL。

3、在<activeProfiles>标签内添加nexus配置, 如下所示

<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>

第二种方式:

[root@localhost ~]# vim /usr/local/maven/conf/settings.xml

<profiles>
    <!-- 公司的私有仓库 -->
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>nexus</id>
          <name>Nexus Repository</name>
          <url>https://your-nexus-repo-url</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
    <!-- 阿里云Maven仓库 -->
    <profile>
      <id>aliyun</id>
      <repositories>
        <repository>
          <id>aliyun</id>
          <name>Aliyun Repository</name>
          <url>https://maven.aliyun.com/nexus/content/groups/public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
</profile>
  </profiles>
  <!-- 激活仓库 -->
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
    <activeProfile>aliyun</activeProfile>
  </activeProfiles>

注意:把https://your-nexus-repo-url替换为实际的Nexus仓库URL。

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信公众号
微信扫一扫,关注我!
weinxin
小柒博客
  • 本文由 小柒博客 发表于 2023年10月17日17:36:56
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/9774.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证