My maven module A has a dependency on another maven module B provided by other people. When I run "mvn install" under A for the first time, maven downloads B-1.0.jar from a remote repository to my local maven repository. My module A builds fine.
我的maven模块A依赖于其他人提供的另一个maven模块B.当我第一次在A下运行“mvn install”时,maven将B-1.0.jar从远程存储库下载到我的本地maven存储库。我的模块A构建良好。
In the mean time, other people are deploying newer B-1.0.jar to the remote repository. When I run "mvn install" under A again, maven does not download the newer B-1.0.jar from the remote repository to my local repository. As a result, my module A build fails due to API changes in B-1.0.jar.
与此同时,其他人正在将更新的B-1.0.jar部署到远程存储库。当我再次在A下运行“mvn install”时,maven不会将较新的B-1.0.jar从远程存储库下载到我的本地存储库。因此,由于B-1.0.jar中的API更改,我的模块A构建失败。
I could manually delete B-1.0.jar from my local repository. Then maven would download the latest B-1.0.jar from the remote repository the next time when I run "mvn install".
我可以从我的本地存储库手动删除B-1.0.jar。然后当我运行“mvn install”时,maven会从远程存储库下载最新的B-1.0.jar。
My question is how I can automatically let maven download the latest artifacts from a remote repository. I tried to set updatePolicy to "always". But that did not do the trick.
我的问题是如何自动让maven从远程存储库下载最新的工件。我试图将updatePolicy设置为“always”。但那并没有成功。
2 个解决方案
#1
28
Maven never re-downloads releases - 1.0 is considered final and new releases should use a new version.
Maven永远不会重新下载版本 - 1.0被认为是最终版本,新版本应该使用新版本。
If the module B is still under development, you should use the version 1.0-SNAPSHOT - snapshots are a special Maven version that will check for updates, and when deployed is stored with the timestamp and build number for tracking.
如果模块B仍处于开发阶段,则应使用版本1.0-SNAPSHOT - 快照是一个特殊的Maven版本,它将检查更新,并在部署时与时间戳和内部版本号一起存储以进行跟踪。
#2
2
I agree with Brett, above: new releases should use new versions. For your case, snapshots are probably the best solution but something else that might also be helpful is to use dependency version ranges.
我同意上面的Brett:新版本应该使用新版本。对于您的情况,快照可能是最好的解决方案,但其他可能也有帮助的是使用依赖版本范围。
Thereby you can specify a version of(1.0,)
stating that you accept any version greater than 1.0.
or[1.1.1,1.1.7]
accepting anything between (including) versions 1.1.1 and 1.1.7.
The notation follows standard math interval syntax where
因此,您可以指定(1.0,)的版本,声明您接受任何大于1.0的版本。或[1.1.1,1.1.7]接受(包括)版本1.1.1和1.1.7之间的任何内容。符号遵循标准数学区间语法,其中
[ = inclusion in the interval
( = exclusion from the interval
[=包含在间隔中(=从间隔中排除)
(in school, I always thought of the square brackets as "holding" that element in, while the softer parenthesis "let it go")
(在学校里,我总是把方括号视为“持有”那个元素,而更柔和的括号“让它走了”)
This can be helpful in cases where your dependencies are still under frequent development and you don't want to rely on new snapshots that might be less stable and more likely to break your code. You can specify the safe ranges and adjust the boundaries up or down, as appropriate, over time
在依赖性仍处于频繁开发状态且您不希望依赖可能不太稳定且更有可能破坏代码的新快照的情况下,这可能会有所帮助。您可以指定安全范围并根据需要向上或向下调整边界
#1
28
Maven never re-downloads releases - 1.0 is considered final and new releases should use a new version.
Maven永远不会重新下载版本 - 1.0被认为是最终版本,新版本应该使用新版本。
If the module B is still under development, you should use the version 1.0-SNAPSHOT - snapshots are a special Maven version that will check for updates, and when deployed is stored with the timestamp and build number for tracking.
如果模块B仍处于开发阶段,则应使用版本1.0-SNAPSHOT - 快照是一个特殊的Maven版本,它将检查更新,并在部署时与时间戳和内部版本号一起存储以进行跟踪。
#2
2
I agree with Brett, above: new releases should use new versions. For your case, snapshots are probably the best solution but something else that might also be helpful is to use dependency version ranges.
我同意上面的Brett:新版本应该使用新版本。对于您的情况,快照可能是最好的解决方案,但其他可能也有帮助的是使用依赖版本范围。
Thereby you can specify a version of(1.0,)
stating that you accept any version greater than 1.0.
or[1.1.1,1.1.7]
accepting anything between (including) versions 1.1.1 and 1.1.7.
The notation follows standard math interval syntax where
因此,您可以指定(1.0,)的版本,声明您接受任何大于1.0的版本。或[1.1.1,1.1.7]接受(包括)版本1.1.1和1.1.7之间的任何内容。符号遵循标准数学区间语法,其中
[ = inclusion in the interval
( = exclusion from the interval
[=包含在间隔中(=从间隔中排除)
(in school, I always thought of the square brackets as "holding" that element in, while the softer parenthesis "let it go")
(在学校里,我总是把方括号视为“持有”那个元素,而更柔和的括号“让它走了”)
This can be helpful in cases where your dependencies are still under frequent development and you don't want to rely on new snapshots that might be less stable and more likely to break your code. You can specify the safe ranges and adjust the boundaries up or down, as appropriate, over time
在依赖性仍处于频繁开发状态且您不希望依赖可能不太稳定且更有可能破坏代码的新快照的情况下,这可能会有所帮助。您可以指定安全范围并根据需要向上或向下调整边界