views:

56

answers:

2

Yesterday I asked about using an exlusive maven repository, now it turns I need to use 2, they are both private .. so concerning this link which explains about forcing maven to use one repository, how do I specify the second repository? Lets take for instance I have two of these repositories in my pom.xml now, if something is missing in the two repositories it will go and search the dependency on the public repository, how to prevent this?

<repositories>
    <repository>
      <id>my-internal-site</id>
      <name>our maven repository</name>
      <url>http://myserver/repo&lt;/url&gt;
    </repository>
 <repository>
      <id>my-other-internal-site</id>
      <name>our 2nd maven repository</name>
      <url>http://myserver/repo2&lt;/url&gt;
    </repository>
  </repositories>

Would I need to alter the setting xml as this?

<settings>
  ...
  <mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>our maven repository</name>
      <url>http://myserver/repo&lt;/url&gt;
      <mirrorOf>my-internal-site,my-other-internal-site</mirrorOf>
    </mirror>
    <mirror>
      <id>my-other-internal-site</id>
      <name>our 2nd maven repository</name>
      <url>http://myserver/repo2&lt;/url&gt;
      <mirrorOf>my-internal-site,my-other-internal-site</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

Or in some other way ?

EDIT

I know that I don't need to set repositories in my pom.xml if I specify exclusive ones in settings.xml .. I'm just making a point so someone can answer my question better.. thank you

+2  A: 

I'd still use:

<settings>
  ...
  <mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy&lt;/url&gt;
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

And add the other internal repository as a "Proxy Repository" (most repository managers can proxy repositories) in the first one.

But I wonder why you have to do this. Can't all projects use the same internal repository?

Pascal Thivent
@Pascal Thivent `But I wonder why you have to do this. Can't all projects use the same internal repository?` sure they can if you asked me, but no one does :D I just get the update how to do it .. do you know where can I read more about proxy repositories, I didn't google anything useful so far.. can I add proxy repository from pom or settings instead of using gui ?
c0mrade
@c0mrade I've added a link to the Nexus documentation (you are using Nexus, right?). And maybe I wasn't clear but this is pure Nexus configuration, i.e. pure Nexus stuff, you can't do it at the pom or settings level (at least not what I'm suggesting).
Pascal Thivent
@Pascal Thivent no we use Artifactory(http://www.jfrog.org/products.php) , and I don't have permissions except for read from repository, other guy does that .. I'm responsible for successful builds for now .. as I understood .. I need to make reference to 2 repositories, and then add their id separated by comma in mirrorOf in settings.xml?
c0mrade
+1  A: 

You don't need to duplicate the repository in mirrors - the configuration you illustrated would have no effect with only one of the mirrors being selected for given mirrorOf.

Mirrors replace repositories already defined, either for a given ID or a collection of IDs (external:*, etc.). If you need to add a repository, you must add a repository element either in the POM or in the settings.

You probably want something like this:

<settings>
  ...
  <profiles>
    <profile>
      <id>second-repo</id>
      <repositories>
        <repository>
          <id>second-repo</id>
          <url>http://myrepo/second-repo&lt;/url&gt;
          <!-- add releases / snapshots config as appropriate here -->
        </repository>
      </repositories>
      <!-- duplicate for pluginRepositories here if needed -->
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>second-repo</activeProfile>
  </activeProfiles>
  ...
  <mirrors>
    <mirror>
      <id>corporate-repo</id>
      <url>http://myrepo/my-group&lt;/url&gt;
      <mirrorOf>external:*,!second-repo</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>
Brett Porter
Ah yes, of course!
Pascal Thivent