简体   繁体   English

如何为离线构建自动更新本地 Maven 存储库 .m2 文件夹

[英]How to auto-update local maven repository .m2 folder for offline build

I am working on a large project which has lots of dependencies and many of them are SNAPSHOT dependencies.我正在处理一个有很多依赖项的大型项目,其中许多是 SNAPSHOT 依赖项。 And because of snapshot dependencies, build takes a huge amount of time (around an hour) as for each dependency it needs to check if it is updated in the remote artifactory or not, even if the snapshot version is not changed.并且由于快照依赖关系,构建需要大量时间(大约一个小时),因为对于每个依赖项,它需要检查它是否在远程工件中更新,即使快照版本没有更改。 With release versions, there is no problem as only if the version is updated then only remote is checked else locally available jars from .m2 is used.对于发布版本,没有问题,因为只有在版本更新时才检查远程,否则使用 .m2 中的本地可用 jar。

Compared to the above scenario, if I do offline build with -o flag when I have all the dependencies available in my local .m2, the build takes only about 5-10 minutes, which saves around 40-45 minutes of build time.与上述场景相比,如果我在本地 .m2 中拥有所有可用依赖项时使用 -o 标志进行离线构建,则构建只需要大约 5-10 分钟,这节省了大约 40-45 分钟的构建时间。 But as the project is large and many people are working on it, whenever I pull changes, there may be some code-changes which requires the latest snapshot and offline build breaks as even a single mismatch can cause build break.但是由于项目很大而且有很多人在做,所以每当我拉更改时,可能会有一些代码更改需要最新的快照和离线构建中断,因为即使是单个不匹配也可能导致构建中断。

So to solve this, I am thinking about the following approach : 1. Always build offline using -o flag.因此,为了解决这个问题,我正在考虑以下方法: 1. 始终使用 -o 标志离线构建。 2. Create some external script (probably in nodejs), which will periodically keep scanning if dependecies given in pom is updated on the remote artifactory. 2. 创建一些外部脚本(可能在 nodejs 中),如果 pom 中给出的依赖项在远程工件上更新,它将定期保持扫描。 If yes, pull into local .m2, else do nothing.如果是,拉入本地.m2,否则什么都不做。

Is there any better alternative to this ?有没有更好的选择呢? Also once I figure out which artifact to update, what is the way using which I can force update only that particular artifact without transitive dependencies?此外,一旦我确定要更新哪个工件,我可以使用什么方法强制更新该特定工件而没有传递依赖关系? With above approach, there is still chance of build break if any transitive dependencies are changed, but that would not happen frequently, and I would have to run full online build in that case.使用上述方法,如果任何传递依赖项发生更改,仍然有可能导致构建中断,但这不会经常发生,在这种情况下我将不得不运行完整的在线构建。

I thought about setting up local proxy artifactory server, but it won't help in this scenario as for snapshot resolution it would any way go to the remote repository.我考虑过设置本地代理工件服务器,但在这种情况下它无济于事,因为对于快照解析,它无论如何都会转到远程存储库。 If I keep cache time longer there is again chances of loosing changes and build break.如果我将缓存时间保持更长的时间,则有可能再次丢失更改和构建中断。

You can control snapshots checking:您可以控制快照检查:

Download policy下载政策

updatePolicy String The frequency for downloading updates - can be "always", "daily" (default), "interval:XXX" (in minutes) or "never" (only if it doesn't exist locally). updatePolicy String 下载更新的频率 - 可以是“always”、“daily”(默认)、“interval:XXX”(以分钟为单位)或“never”(仅当它在本地不存在时)。

https://maven.apache.org/ref/3.6.3/maven-settings/settings.html#class_snapshots https://maven.apache.org/ref/3.6.3/maven-settings/settings.html#class_snapshots

But probably you have some other issue, since 45 mins for build wasted on downloading artifacts is a lot.但您可能还有其他问题,因为在下载工件上浪费了 45 分钟的构建时间。

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

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