在 Travis CI 上访问 mvnsearch.org 时如何避免 "The job exceeded the maximum time limit for jobs, and has been terminated."?

How to avoid "The job exceeded the maximum time limit for jobs, and has been terminated." when accessing mvnsearch.org on Travis CI?

从大约。 72h 我在 TravisCI 上收到 The job exceeded the maximum time limit for jobs, and has been terminated.,这似乎与从 mvnsearch.org 请求工件有关,例如https://travis-ci.org/document-scanner/document-scanner-aggregator/builds/266942578。我假设它是一个我没有使用的远程存储库,但项目的一些依赖项是。

mavensearch.org 似乎无法访问或响应速度非常慢。我没有找到任何关于他们运营状况的消息。奇怪的是问题没有在 72 小时内解决,所以我认为这是一个长期问题。

我能想到的唯一可能的解决方案是将 Maven 代理的下载和安装添加到 Maven settings.xml 文件中的 Travis CI 构建脚本和代理 mavensearch.org .有什么办法可以避免这种情况吗?

~/.m2/settings.xml 中使用 mirror 元素不起作用,因为它引用了引用的 POM 中的存储库 ID,它可以是传递依赖项,并且可以在使用和需要快照时更改在每次版本更改后进行检查并最终进行调整。

可以执行几个操作:

  1. Common Build Problems: My builds are timing out - Travis CI answer provides a couple of solutions. One of them is «to extend the wait time» for the Maven process.
  2. 启用 Maven 依赖项的缓存:Caching Dependencies and Directories: Caching directories (Bundler, dependencies): Arbitrary directories - Travis CI.
  3. 使用存储库管理器:«act as dedicated proxy server for public Maven repositories»
    其他参考资料:
    1. 关系示例:
    2. 一般问题:How does one mirror a maven repository?.

通过添加

在 Travis CI 上启用缓存
cache:
  directories:
  - $HOME/.m2

.travis.yml 结果根本不是解决方案或只是一个临时解决方案(上周大约 40 个构建;因为 mvnsearch.org 再次可用或由于其他原因很难弄清楚),我发现了以下更有前途的解决方案(这比设置可用作镜像的 Nexus 存储库管理器实例容易得多):

添加

- echo -e '<?xml version="1.0" encoding="UTF-8"?>\n<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"\n    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n  <mirrors>\n    <mirror>\n      <id>mvnsearch-unavailable</id>\n      <name>mvnsearch-unavailable</name>\n      <mirrorOf>mvnsearch</mirrorOf>\n      <url>http://repo1.maven.org/maven2</url>\n    </mirror>\n  </mirrors>\n  <profiles>\n    <profile>\n      <id>no-mvnsearch</id>\n      <repositories>\n        <repository>\n          <id>mvnsearch</id>\n          <url>http://www.mvnsearch.org/maven2</url>\n          <releases>\n            <enabled>true</enabled>\n          </releases>\n          <snapshots>\n            <enabled>true</enabled>\n          </snapshots>\n        </repository>\n      </repositories>\n    </profile>\n  </profiles>\n  <activeProfiles>\n    <activeProfile>no-mvnsearch</activeProfile>\n  </activeProfiles>\n</settings>' > $HOME/.m2/settings.xml
- cat $HOME/.m2/settings.xml

.travis.yml 这将在任何难以控制的传递依赖项中覆盖 http://www.mvnsearch.org/maven2 的使用,并使用涵盖我案例中所有依赖项的 Maven 中央存储库 http://repo1.maven.org/maven2 (它可能不会在其他情况下)。

请注意,墨菲定律适用于任何事情:Maven 3.1.1 忽略此设置,即使它声称在其调试输出中使用镜像(哎哟!)。

构建现在比使用临时工作缓存解决方案快 7 分钟。