Maven配置多个仓库地址

在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。

原创文章,作者:admin,如若转载,请注明出处:https://hostingchat.cn/1774.html

(0)
admin的头像admin
上一篇 2023年10月13日 下午4:50
下一篇 2023年11月7日 下午5:50

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注