【问题标题】:How to use the internet for maven builds instead, if the corporate maven repository is offline or down?如果公司 maven 存储库脱机或关闭,如何使用 Internet 进行 maven 构建?
【发布时间】:2014-06-26 02:13:29
【问题描述】:

我在我的 POM 中定义了一个公司存储库:

<distributionManagement>
    <repository>
        <id>central</id>
        <name>libs-release-local</name>
        <url>http://bi-pub.wgresorts.com:8081/artifactory/libs-release-local</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>libs-snapshot-local</name>
        <url>http://bi-pub.wgresorts.com:8081/artifactory/libs-snapshot-local</url>
        <uniqueVersion>false</uniqueVersion>
    </snapshotRepository>
</distributionManagement>

但他们一直在拔下并移动或重新启动那个盒子,所以有时它不可用。有没有办法告诉我的 maven poms “尝试使用公司存储库,但如果它关闭了使用互联网?”我尝试在分发管理部分之外指定存储库和插件存储库,但无济于事。

请问有人可以指导吗?

在 settings.xml 我定义了一个镜像和一个本地存储库:

<mirrors>
    <mirror>
        <mirrorOf>*</mirrorOf>
        <name>repo</name>
        <url>http://bi-pub.wgresorts.com:8081/artifactory/repo</url>
        <id>repo</id>
    </mirror>
</mirrors>

<localRepository>C:\apache-maven-3.1.1\.m2\repository</localRepository>

我不想根据 IT 部门的突发奇想不断更改 settings.xml,我可以设置它以便它尝试公司的网络在它出现故障时上网吗?

编辑

如果您使用了 id central,则必须先创建一个带有 central 的 pom,该 pom 指向 Internet 上真实的 pom,然后才能解决此问题。它还可以指向您的公司存储库,但具有不同的 ID。然后,如果您的公司存储库出现故障,它将掉入互联网。

我认为您可能还必须从 settings.xml 中删除镜像部分

【问题讨论】:

标签: maven repository pom.xml offline artifactory


【解决方案1】:

首先你的 settings.xml 文件不正确。

<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

您必须使用上面的定义来表示 maven 来搜索工件以及镜像存储库中的插件(不管它是连接还是工件)。

作为补充,您定义了uniqueVersion,其中包含no effect starting with Maven 3

除了setting.xml 中的定义用于读取,而pom.xml distributionManagement 中的定义用于写入,这意味着部署工件或站点。

因此,在这两种情况下,您都需要像 JBaruch 提到的那样启动并运行存储库。如果您的 IT 部门无法处理此类情况(基本 IT 操作),我几乎不会考虑这一点。

贵公司的每个构建都依赖于存储库管理器的可用性,用于下载工件或部署构建结果以及遵循管道的步骤。

【讨论】:

  • 但即使 nexus/artifactory 关闭,我也应该能够构建。我了解部署被破坏,但肯定有一种方法不必完全依赖于一台服务器的启动。我将删除 uniqueVersion。还有为什么说是错的?我有 4 个存储库,2 个用于发布,2 个用于快照,分别用于插件和其他工件。这是默认配置,我没有修改过。
  • 如果您已经构建了项目的状态,您可以通过mvn --offline 离线,因此您无需联系您的 neuxs/artifactory。
  • 但是如果它发生在你可以做 mvn --offline 之前你怎么能恢复呢?
【解决方案2】:

无论好坏,二进制存储库都是生产管道的关键部分。 您不会问“如果我的网站出现故障,我有什么选择”,是吗?您只需保持您的网站正常运行。同样的故事,您的 IT 部门应该意识到这一点。

您可以在 DR 模式(主动/被动)甚至 HA 模式(主动/主动)下运行 Artifactory。您的存储库拥有 24/7 全天候运行的所有方法,因此您真的不需要这些变通方法。

【讨论】:

  • 遗憾的是,您高估了我们的能力/服务器可靠性(必须共享硬件):
  • 我只能指出我之前给你的相同答案。在不知情的情况下通过 Internet 回退到存储库是一个非常糟糕的主意。
  • 我不确定是什么问题?只需从设置中删除配置文件即可。
  • 我最终删除并重新创建了存储库和我的 Maven 设置文件,因为元数据似乎已损坏。如果您在公司服务器出现故障之前不脱机,则似乎很难从该状态中恢复。这似乎是一个普遍的问题。我想知道为什么这个问题没有投票权。
猜你喜欢
  • 1970-01-01
  • 2019-01-09
  • 1970-01-01
  • 1970-01-01
  • 2011-03-07
  • 2020-07-19
  • 2019-02-06
  • 2012-01-12
  • 2012-09-19
相关资源
最近更新 更多