【Maven】配置多個倉庫(第三方和公司內部倉庫)

中国制造發表於2024-03-27
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">

  <localRepository>D:\Develop\.m2\repository</localRepository>

  <mirrors>
    <!-- 刪除mirrors裡的配置,改用profiles -->
  </mirrors>

  <profiles>
    <!-- 多倉庫配置  -->
    <!-- 阿里雲 -->
    <profile>
      <id>aliyun</id>
      <repositories>
        <repository>
          <!-- 注意:repository的id不要重複,否則先解析的配置會被後解析的覆蓋 -->
          <id>aliyun-public</id>
          <url>https://maven.aliyun.com/repository/public</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>

    <!-- 公司內網 -->
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>nexus-public</id>
          <url>http://公司倉庫地址</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>nexus-central</id>
          <url>http://公司倉庫地址</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <!-- 需要預設啟用的遠端映象倉庫配置 -->
  <activeProfiles>
    <activeProfile>aliyun</activeProfile>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

</settings>

相關文章