我可以从同一个POM中的一个repo和第二个repo中解析一个Maven依赖项吗?

时间:2016-07-02 20:50:30

标签: maven repository dependency-management

我们有一个包含多个父/子POM的项目。所有POM都指向一个存储库,用于解析所有Maven依赖项。

现在我有一个需要:在一个POM中,必须从repo1下载一个jar并从repo2中休息4-5个罐子。

你怎么能这样做?

2 个答案:

答案 0 :(得分:2)

总之 - 是的。 Maven的依赖解析机制与存储库机制完全分离。从理论上讲,你可以从自己的存储库中提供每一个jar(但实际上这可能是荒谬的)。

答案 1 :(得分: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>