简体   繁体   English

使用多个公司存储库

[英]Using multiple corporate repositories

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? 昨天我问到使用一个exlusive maven存储库,现在我需要使用2,它们都是私有的..所以关于这个链接解释了强制maven使用一个存储库,我该如何指定第二个存储库? 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? 让我们看看,我现在在我的pom.xml中有两个这样的存储库,如果两个存储库中缺少某些存储库,它将搜索公共存储库的依赖关系,如何防止这种情况?

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

Would I need to alter the setting xml as this? 我需要改变设置xml吗?

<settings>
  ...
  <mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>our maven repository</name>
      <url>http://myserver/repo</url>
      <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</url>
      <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 我知道如果我在settings.xml中指定独占的,我不需要在我的pom.xml中设置存储库。我只是说明一点,所以有人可以更好地回答我的问题..谢谢

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 . 您不需要在镜像中复制存储库 - 您所说明的配置对于给定mirrorOf仅选择了一个镜像mirrorOf

Mirrors replace repositories already defined, either for a given ID or a collection of IDs ( external:* , etc.). 镜像替换已定义的存储库,用于给定ID或ID集合( external:*等)。 If you need to add a repository, you must add a repository element either in the POM or in the settings. 如果需要添加存储库,则必须在POM或设置中添加存储库元素。

You probably want something like this: 你可能想要这样的东西:

<settings>
  ...
  <profiles>
    <profile>
      <id>second-repo</id>
      <repositories>
        <repository>
          <id>second-repo</id>
          <url>http://myrepo/second-repo</url>
          <!-- 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</url>
      <mirrorOf>external:*,!second-repo</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

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</url>
      <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? 不能所有项目都使用相同的内部存储库吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM