2016-07-02 74 views
1

我們有一個有多個家長/孩子POM的項目。所有POM都指向一個用於解決所有Maven依賴關係的存儲庫。我可以在一個POM中解析一個Maven依賴關係和另一個依賴關係嗎?

現在我有這樣的需求:在一個POM中,一個罐子必須從repo1下載,其餘的4-5罐子從repo2下載。

你怎麼能這樣做?

+1

pom永遠不會指向存儲庫。一個pom聲明倉庫(這是不好的做法)。您應該使用存儲庫管理器來處理該問題。在你的poms中,通常不應該定義任何倉庫。只有在settings.xml中,您應該定義存儲庫或最好只有一個用於解決由Neuxs等存儲庫管理器在後臺處理依賴項的組。 – khmarbaise

+2

@khmarbaise如果這是不好的做法,爲什麼[設置參考,服務器](https://maven.apache.org/settings.html#Servers)說:「_下載和部署的存儲庫被定義_ [sic!not _declared_? ] _是POM._的'repositories'和'distributionManagement'元素?而且,我知道,_declaring_是POM的正式用詞(由於它們的陳述性質),但你爲什麼認爲指向那麼糟? –

回答

0
What I have understand the, 
I can setup maven repo in artifactory/nexus 
e.g. http://localhost:18081/artifactory/ --> L1 

1. create remote(R1) repository in artifactory, which can point URL to outside repository, hosted by artifactory/nexus 
e.g http://remotehost:18081/artifactory/remote-repo1 

2. create a "virtual" repository(V1) in my artifactory and add remote(R1) in to this V1. 
3. Let all my poms points to my local artifactory virtual repository(V1), 
e.g.>http://localhost:18081/artifactory/virtual 

that way, maven will look 
a. local .m2 folder 
b. then look for jars in virtual repo of my artifactory 
hence virtual will look 
    b1. all local repo 
    b2. all remote cache repo 
    b3. all remote repo --> e.g.http://remotehost:18081/artifactory/remote-repo1 

I am experimenting this,once succeed, i will update 
EDIT : 
This has worked for me, the only hiccup I faced was my ~/.m2/settings.xml 
the snapshot was false, and my jar in remote repo is a snapshot jar. 
After changing this value to true, now its fetching the jars :) 
</profile> 
       <profile> 
         <id>virtual-repo</id> 
         <repositories> 
           <repository> 
             <id>central</id> 
              <url><repo_url></url> 
             <snapshots> 
               **<enabled>true</enabled>** 
             </snapshots> 
           </repository> 
         </repositories> 
+0

這對我來說很有效,我遇到的唯一一個呃逆是我的〜/ .m2/settings.xml – sandejai

2

總而言之 - 是的。 Maven的依賴解決機制與存儲庫機制完全分離。從理論上講,你可以從自己的倉庫提供每一個罐子(但實際上可能會這樣做是荒謬的)。

+0

你可以分享標籤嗎? 因爲我無法看到任何與pom文件中標記中的回購網址相關的標籤 – sandejai