sandejai
sandejai

Reputation: 989

Can I resolve one Maven dependency from one repo and another dependency from second repo in same POM?

We have a project with multiple parent/child POMs. All the POMs are pointing to a single repository for resolving all Maven dependencies.

Now I have a need like: In a single POM, one jar has to be downloaded from repo1 and rest 4-5 jars from repo2.

How can you do that?

Upvotes: 1

Views: 1278

Answers (2)

sandejai
sandejai

Reputation: 989

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>

Upvotes: 0

Mureinik
Mureinik

Reputation: 311883

In a word - yes. Maven's dependency resolution mechanism is completely separate from the repository mechanism. Theoretically, you could have every single jar delivered from its own repository (however ridiculous it may to actually do this).

Upvotes: 2

Related Questions