1. 程式人生 > 程式設計 >maven 配置多個倉庫的方法

maven 配置多個倉庫的方法

1>方法一

之前在配置 Maven 的 settings.xml 時,都會設定 mirror 節點,例如:

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

然後第一想法就是在 mirrors 節點下多增加幾個 mirror,然而並不可以。正確的操作是在 profiles 節點下配置多個 profile,而且配置之後要啟用。例如:

配置profiles

<profiles>
  <profile>
   <id>boundlessgeo</id> 
   <repositories>
    <repository>
     <id>boundlessgeo</id> 
     <url>https://repo.boundlessgeo.com/main/</url> 
     <releases>
      <enabled>true</enabled>
     </releases> 
     <snapshots>
      <enabled>true</enabled> 
      <updatePolicy>always</updatePolicy>
     </snapshots>
    </repository>
   </repositories>
  </profile>
  <profile>
   <id>aliyun</id> 
   <repositories>
    <repository>
     <id>aliyun</id> 
     <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 
     <releases>
      <enabled>true</enabled>
     </releases> 
     <snapshots>
      <enabled>true</enabled> 
      <updatePolicy>always</updatePolicy>
     </snapshots>
    </repository>
   </repositories>
  </profile> 
  <profile>
   <id>maven-central</id> 
   <repositories>
    <repository>
     <id>maven-central</id> 
     <url>http://central.maven.org/maven2/</url> 
     <releases>
      <enabled>true</enabled>
     </releases> 
     <snapshots>
      <enabled>true</enabled> 
      <updatePolicy>always</updatePolicy>
     </snapshots>
    </repository>
   </repositories>
  </profile>
<profiles>

通過配置 activeProfiles 子節點啟用

<activeProfiles>
  <activeProfile>boundlessgeo</activeProfile>
  <activeProfile>aliyun</activeProfile>
  <activeProfile>maven-central</activeProfile>
</activeProfiles>

如果在IDE裡,記得要更新生效,然後就可以了。

2> 方法二

在專案中新增多個倉庫,是通過修改專案中的pom檔案實現的。

思路:在專案中pom檔案的repositories節點(如果沒有手動新增)下新增多個repository節點,每個repository節點是一個倉庫。

<repositories>
    <repository>
      <!-- id必須唯一 -->
      <id>jboss-repository</id>
      <name>jboss repository</name>
      <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
    </repository>
    <repository>
      <id>aliyun-repository</id>
      <name>aliyun repository</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </repository>
 
 
    <repository>
     <id>奇葩倉庫</id>
     <url>https://奇葩倉庫/public/</url>
    </repository>
 
  </repositories>

到此這篇關於maven 配置多個倉庫的方法的文章就介紹到這了,更多相關maven 多個倉庫配置內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!