2011-09-15 46 views
16

我們正嘗試使用Archiva作爲中央和其他外部存儲庫的Maven代理,並且還將其作爲我們的工件的快照存儲,這些工件由Hudson從SVN自動構建並安裝到快照存儲庫。如何爲Maven設置Archiva內部+快照存儲庫?

我無法設置我的Maven客戶端使用內部和快照存儲庫在一起。我的項目有一些外部依賴項(如log4j),它們正確地從Archiva內部存儲庫下載。此外,我的項目對自己的項目具有依賴性,該項目的構件已經構建並安裝到快照庫。但是,如果我嘗試構建項目Maven無法找到我的快照神器。

我的配置文件中原本有此設置:

<mirror> 
    <id>company-internal</id> 
    <name>Company's Archiva - Internal Repository</name> 
    <url>http://www.mycompany.hu/archiva/repository/internal</url> 
    <mirrorOf>*</mirrorOf> 
</mirror> 

,然後我增加了以下內容:

<mirror> 
<id>company-snapshots</id> 
<name>Company Archiva - Snapshots Repository</name> 
<url>http://www.mycompany.hu/archiva/repository/snapshots</url> 
<mirrorOf>apache.snapshots</mirrorOf> 
</mirror> 

但是Maven不包括嘗試查找的snaphot庫在構建。 我做錯了什麼?順便說一句,我沒有真正獲得<mirrorOf>元素的用途。我試圖用內部鏡像設置替換爲central,但這仍然無法解決我的問題。

回答

16

經過一些試驗和錯誤之後,以下配置適用於我。在這裏,我使用默認的archiva配置 - internal來保存版本,snapshots只保存內部快照。

本質上不同於nexus我們需要兩個獨立的<mirror><repository>聲明 - 一個用於正常的文物和其他快照文物。

<mirrors> 
    <mirror> 
     <id>archiva</id> 
     <mirrorOf>*</mirrorOf> 
     <url>http://localhost:8080/archiva/repository/internal</url> 
    </mirror> 
    <mirror> 
     <id>snapshots</id> 
     <mirrorOf>snapshots</mirrorOf> 
     <url>http://localhost:8080/archiva/repository/snapshots</url> 
    </mirror> 
</mirrors> 
<profiles> 
    <profile> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <repositories> 
      <repository> 
       <id>internal</id> 
       <name>Archiva Managed Internal Repository</name> 
       <url>http://localhost:8080/archiva/repository/internal/</url> 
       <releases> 
       <enabled>true</enabled> 
       </releases> 
       <snapshots> 
       <enabled>false</enabled> 
       </snapshots> 
      </repository> 
      <repository> 
       <id>snapshots</id> 
       <name>Archiva Managed Internal Repository</name> 
       <url>http://localhost:8080/archiva/repository/snapshots/</url> 
       <releases> 
       <enabled>false</enabled> 
       </releases> 
       <snapshots> 
       <enabled>true</enabled> 
       </snapshots> 
      </repository> 
     </repositories> 
    </profile> 
</profiles> 
+0

謝謝,我會盡快嘗試了這一點。 – NagyI

+0

那麼它還沒有工作。它甚至沒有下載內部文物現在:(這是我的配置,請你看看它?http://pastebin.com/czG8uTFt – NagyI

+0

「你還在嗎?」:) – NagyI

2

通過大量的試驗和錯誤,我得到了一個非常類似於Raghuram's的配置。然而,通過使用檔案,我發現了一兩件可能仍值得注意的事情。另外,我使用配置中的鏡像來訪問我的項目(在pom.xml中設置爲<distributionManagement/>),而不是直接訪問存儲庫。

這是我的Maven的settings.xml的相關部分:

<!-- set up servers to point to mirror, for use in project pom --> 
<servers> 
    <server> 
    <id>my.snapshots</id> <!-- use name of the mirror here --> 
    <username>user</username> 
    <password>pwd</password> 
    </server> 
</servers> 

<!-- map mirror names to actual repositories --> 
<mirrors> 
    <!-- leave the default mirror in place --> 
    <mirror> 
    <id>archiva.default</id> 
    <mirrorOf>*</mirrorOf> 
    <url>http://server:port/archiva/repository/internal/</url> 
    </mirror> 
    <!-- enter my own --> 
    <mirror> 
    <id>my.snapshots</id> 
    <mirrorOf>archiva.snapshots</mirrorOf> 
    <url>http://server:port/archiva/repository/snapshots/</url> 
    </mirror> 
<mirrors> 

<!-- activate the repo for artifact downloads by setting profile --> 
<profiles> 
    <activation> 
    <activeByDefault>true</activeByDefault> 
    </activation> 
    <repositories> 
    <repository> <!-- mirror will be used during runtime instead of this --> 
     <id>archiva.snapshots</id> <!-- do not use mirror name here --> 
     <url>http://server:port/archiva/repository/snapshots/</url> 
     <releases> 
     <enabled>false</enabled> 
     </releases> 
     <snapshots> 
     <enabled>true</enabled> 
     </snapshots> 
    </repository> 
    </repositories> 
</profile> 

我發現我在比<profiles>部分<mirrors>部分給予不同的ID,所以我貌似是不允許給他們和拉古拉姆一樣的名字。

現在,在settings.xml中,我着手更改項目的pom.xml中的<distributionManagement>部分。準確地說,我在一個pom中更改了這個設置,這是我所有項目的父項:它主要包含<distributionManagement>部分和其他部分。這個父pom本身被部署到archiva。

這是父pom的相關部分。XML:

<distributionManagement> 
    <repository> 
    ... 
    </repository> 
    <snapshotRepository> 
    <id>my.snapshots</id> 
    <name>Archiva Managed Snapshot Repository</name> 
    <url>http://server:port/archiva/repository/snapshots</url> 
    <layout>default</layout> 
    </snapshotRepository> 
</distributionManagement> 

這種精簡的東西,它,我認爲,一些好處:

  • 我現在能夠建立項目根據我自己的文物(包括父POM),而不是在我的本地構建庫中有任何這些工件(我擦拭了我的本地資源庫以測試它)。

  • 現在通過鏡像處理下載(pom.xml的<dependencies>部分)以及上傳(pom.xml的<distributionManagement>部分)。

1

通過大量的試驗和錯誤我也來到了一個以上的事情,但對我來說didnt鍛鍊頗爲相似的配置,直到我這樣做如下配置。因此,如果您在組織存儲庫的幫助下使用maven,而不是在本地主機上使用,則會發布它以嘗試改進答案。

這個答案適用於那些需要爲您的組織維護多個存儲庫的多個鏡像配置的人,那麼這將作爲示例。

my.snapshots 用戶 PWD

<!-- map mirror names to actual repositories --> 
<mirrors> 
    <!-- enter my own --> 
    <mirror> 
    <id>my.snapshots</id> 
    <mirrorOf>archiva.snapshots</mirrorOf> <!-- this name should be the same as configured for the below repository id.> 
    <url>http://server:port/archiva/repository/snapshots/</url> 
    </mirror> 
    <!-- leave the default mirror in place --> 
    <mirror> 
    <id>archiva.default</id> 
    <mirrorOf>central</mirrorOf> < !-- Instead of *, replace it with "central"--> 
    <url>http://server:port/archiva/repository/internal/</url> 
    </mirror> 
<mirrors> 

<!-- activate the repo for artifact downloads by setting profile --> 
<profiles> 
    <activation> 
    <activeByDefault>true</activeByDefault> 
    </activation> 
    <repositories> 
    <repository> <!-- mirror will be used during runtime instead of this --> 
     <id>archiva.snapshots</id> <!-- do not use mirror name here --> 
     <url>http://server:port/archiva/repository/snapshots/</url> 
     <releases> 
     <enabled>false</enabled> 
     </releases> 
     <snapshots> 
     <enabled>true</enabled> 
     </snapshots> 
    </repository> 
    </repositories> 
</profile> 
相關問題