英文:
How to automate reliable builds when Maven dependencies are only available for a limited time?
问题
我有一个使用Maven的项目,它有几个依赖项:
- 这些依赖项托管在第三方构件库中,该库只保存最近的
x
个构件。 - 这些依赖项是快照版本。(没有可用的正式发布版本。)
一旦我构建了我的项目,我需要团队中的其他成员在未来几年内仍然能够构建该项目的同一版本。然而:
- 我使用的依赖项快照版本可能不再在第三方构件库中可用。
- 即使可用,依赖项可能已经更新,但快照版本号并未更改。
是否有一种方法可以自动创建一个共享的依赖项构件库,其中包含Maven在首次构建项目时检索的依赖项构件?这将使每个依赖项构件只从第三方构件库中检索一次。
英文:
I have a Maven project which has several dependencies that:
- Are hosted on a third-party artifact repository, which only holds the
x
most recent artifacts. - 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:
- The dependency snapshot version I used may no longer be available on the third-party repository.
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论