如何在Maven依赖仅在有限时间内可用时自动化可靠构建?

huangapple go评论67阅读模式
英文:

How to automate reliable builds when Maven dependencies are only available for a limited time?

问题

我有一个使用Maven的项目,它有几个依赖项:

  1. 这些依赖项托管在第三方构件库中,该库只保存最近的x个构件。
  2. 这些依赖项是快照版本。(没有可用的正式发布版本。)

一旦我构建了我的项目,我需要团队中的其他成员在未来几年内仍然能够构建该项目的同一版本。然而:

  1. 我使用的依赖项快照版本可能不再在第三方构件库中可用。
  2. 即使可用,依赖项可能已经更新,但快照版本号并未更改。

是否有一种方法可以自动创建一个共享的依赖项构件库,其中包含Maven在首次构建项目时检索的依赖项构件?这将使每个依赖项构件只从第三方构件库中检索一次。

英文:

I have a Maven project which has several dependencies that:

  1. Are hosted on a third-party artifact repository, which only holds the x most recent artifacts.
  2. Are snapshot versions. (There are no releases available.)

Once I build my project, I need other members of my team to still build that same version of the project several years from now. However:

  1. The dependency snapshot version I used may no longer be available on the third-party repository.
  2. Even if it's available, the dependency may have been updated without changing the snapshot version number.

Is there a way to automatically create a shared repository of the dependency artifacts Maven retrieved when building the project for the first time? This would cause each dependency artifact to only be retrieved once from the third-party repository.

答案1

得分: 2

在您公司中设置一个 Nexus 或 Artifactory 服务器。

将所有外部仓库添加为 Nexus/Artifactory 的远程仓库,并通过 Nexus/Artifactory 运行所有构建。

Nexus/Artifactory 将缓存您所使用的所有构件,因此不会出现将来某些构件不可用的风险。

对于快照版本:如果您确实需要使用快照版本,在使用之前请使用 versions:lock-snapshots(https://www.mojohaus.org/versions-maven-plugin/lock-snapshots-mojo.html),以便您拥有可重现的版本号。

英文:

Set up a Nexus or Artifactory server in your company.

Add all the external repositories as remote repositories to that Nexus/Artifactory and run all builds through Nexus/Artifactory.

The Nexus/Artifactory will cache all the artifacts you have used, so no risk that some artifact is not available in the future.

For Snapshot version: If you really need to use Snapshot versions, use versions:lock-snapshots (https://www.mojohaus.org/versions-maven-plugin/lock-snapshots-mojo.html) before, so that you have reproducible version numbers.

huangapple
  • 本文由 发表于 2020年8月17日 19:03:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63449571.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定