gpt4 book ai didi

maven-2 - 如何强制maven每天更新依赖的版本?

转载 作者:行者123 更新时间:2023-12-05 08:02:29 29 4
gpt4 key购买 nike

我们正在使用 maven 2.2.1 并且对事情的进展非常满意。最近我们开始像这样使用依赖版本的范围:

    <dependency>
<!-- com.google.inject.Guice -->
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>[3,4)</version>
</dependency>

但现在我面临一个问题,maven 在每次构建时检查每个此类依赖项的新版本,这使得构建非常缓慢:

[INFO] artifact com.google.inject:guice: checking for updates from internal
[INFO] artifact com.google.inject:guice: checking for updates from central

这是我的存储库声明的样子:

<repositories>
<repository>
<id>internal</id>
<url>http://internal.repo.local/nexus/content/repositories/releases</url>
</repository>
</repositories>

据我所知,我检查了存储库配置,查看了 <repository/> 的默认值部分和父 POM 继承。 我已经尝试更改 updatePolicy没有成功。看起来所有政策都只适用于 SNAPSHOT管理并在版本检查中被忽略。

我找到了 -o 的解决方法命令行选项,但是...我想至少有时检查外部版本和创建想法 cron每天更新本地存储库的基于 maven 的调度听起来不是一个合适的解决方案。

最佳答案

首先,正如之前的评论者所说,您的构建无法通过构建范围重现……这就是 Maven 的全部意义所在。我希望你明白那的重要性,所以我只回答你的问题。

只需设置存储库的更新策略:

    <repositories>        <repository>            <id>internal</id>            <url>http://internal.repo.local/nexus/content/repositories/releases</url>            <releases>                <enabled>true</enabled>                <updatePolicy>always</updatePolicy>            </releases>            <snapshots>                <enabled>true</enabled>                <updatePolicy>always</updatePolicy>            </snapshots>        </repository>    </repositories>

编辑:我断章取意地回答了原来的问题,抱歉。

回答这个问题的最好方法是弄清楚为什么 Maven 每天都在更新。这可能是由您的远程依赖引起的,也可能是 Maven 中的错误。我会让你在上面做步法......

我认为您实际上想表达的意思是,“我如何防止每次构建时 maven 都跑到中心并拖慢我的速度?”我在海外工作时遇到了这个问题,互联网连接非常慢。我们设置了一个 Nexus 代理,我必须想出一种方法来强制所有查找都命中代理。

更改为适合您需要的内容。除非您有更具体的需求,否则每日可能会奏效。

接下来,编辑您的 settings.xml 并添加此部分:

    </activeProfiles>    <mirrors>        <mirror>            <id>internal-mirror</id>            <url>http://internal.repo.local/nexus/content/repositories/releases</url>            <mirrorOf>*</mirrorOf>        </mirror>    </mirrors></settings>

这将强制所有依赖项查找通过您的内部 nexus 实例,命中 nexus 缓存,并极大地加快您的构建速度。

关于maven-2 - 如何强制maven每天更新依赖的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6176272/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com