当本地和远程存储库中存在带有不同时间戳的SNAPSHOTS时,Maven如何解决SNAPSHOT依赖关系? [英] How does Maven resolve SNAPSHOT dependencies when there are SNAPSHOTS with different timestamps in the local and the remote repository?

查看:673
本文介绍了当本地和远程存储库中存在带有不同时间戳的SNAPSHOTS时,Maven如何解决SNAPSHOT依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个项目A正在开发中,该项目取决于项目B-该项目也正在开发中,尚未发布.

Say I have a project A in development that depends on project B - which is also currently in development and not yet released.

因此,在A的POM文件中,我有以下部分:

So, in A's POM file, I have the following section:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>project-b</artifactId>
  <version>1.0.0-SNAPSHOT</version>
<\dependency>

在工作中,我们有一个远程存储库(Nexus)和一个CI框(正在运行Jenkins).

At work, we have a remote repo (Nexus) and a CI box (running Jenkins).

当我的同事对B进行更改并提交SVN时,Jenkins将选择该更改,将其编译并放入远程仓库中.大约在那个时候,我可能会在本地打开B进行更改,然后将其编译并安装到我的本地存储库中.

When my colleague makes a change to B and commits to SVN, Jenkins will pick that change up, compile it and put it into the remote repo. Around that time, I might open B locally, make a change, compile it and install it into my local repo.

当我尝试在本地尝试mvn clean install A时,Maven现在如何解析B?

How does Maven now resolve B when I try to mvn clean install A locally?

  • 如果找到本地快照,它将始终默认为我的本地快照吗?
  • 是否始终将其默认设置为远程快照?
  • 会看时间戳吗?
  • 会做一些不同的事情吗?

前几天,我们陷入混乱,基本上必须手动删除本地存储库,以确保获得所需的版本.所以我现在想弄清楚到底发生了什么. (因此,如果您有指向文档中详细位置的链接,也将不胜感激...)在本地,我有时在我的存储库文件夹中有一些SNAPSHOT构建,一个不包含,另一些包含什么在文件名的SNAPSHOT部分之后看起来像是一个时间戳记.

We got ourselves a bit into a mess the other day, and basically had to manually remove the local repositories to ensure we got the version we were expecting to get. So I'm now trying to figure out what really went on. (Therefore, if you have links to places in the docs that go into detail, that, too, would be much appreciated...) Locally, I sometimes have a few SNAPSHOT builds in my repository folder, one without and a few with what looks like a timestamp after the SNAPSHOT part of the file name...

推荐答案

您刚刚获得mvn install的工件没有时间戳.一旦您mvn deploy到内部/远程存储库,便会应用一个时间戳.如果您查看本地~/.m2/repository/B/1.0.0-SNAPSHOT/文件夹中的maven-metadata-local.xml,您将看到带有以下内容的行:

Artifacts that you just mvn install don't get a timestamp. A timestamp is applied once you mvn deploy to your internal/remote repository. If you look into the maven-metadata-local.xml in your local ~/.m2/repository/B/1.0.0-SNAPSHOT/ folder you'll see lines with:

<updated>YYYYMMDDHHMMSS</updated> 

这是Maven依赖解析器确定最新快照的方式.

This is how the Maven dependency resolver decides what the latest snapshot is.

如果您和您的同事在同一秒内部署到内部/远程存储库,则取决于存储库管理器(在您的情况下为Nexus)来处理此问题.

If it happens that you and your colleague deploy to your internal/remote repository within the same second it's up to the repository manager – Nexus in your case – to handle this.

请注意:上面的段落取决于我在Maven上的经验,因为到目前为止我还没有看到任何文档页面,在该文档页面中所有详细信息都没有描述.我们非常欢迎您在其中输入参考文献以及进行补充和更正.

有关概述,请参见 Maven/存储库简介.

如果您要确保使用最新的快照:

If you want to assure that you use the latest snapshots:

  • 相应地在settings.xml中声明<updatePolicy>:

  • updatePolicy :此元素指定应该尝试执行更新的频率. Maven会将本地POM的时间戳(存储在存储库的maven-metadata文件中)与远程进行比较.选项包括:alwaysdaily(默认),interval:X(其中X是分钟内的整数)或never.
  • updatePolicy: This element specifies how often updates should attempt to occur. Maven will compare the local POM’s timestamp (stored in a repository’s maven-metadata file) to the remote. The choices are: always, daily (default), interval:X (where X is an integer in minutes) or never.

请参见设置参考,存储库.

使用-U | --update-snapshots命令行选项.

use the -U | --update-snapshots command line option.

$ mvn -h
...
-U,--update-snapshots    Forces a check for missing
                         releases and updated snapshots on
                         remote repositories
...

另请参见 Maven:完整参考,6.1. Maven命令行选项,6.1.11.下载并验证依赖项.

文件名的SNAPSHOT部分之后的时间戳记" 对我来说是不寻常的. AFAIHS只能是一个或另一个.尽管如果项目的POM中的<artifactId>中有"-SNAPSHOT",则可能会发生这种情况.

„A timestamp after the SNAPSHOT part of the file name" is unusual to me. AFAIHS it's either the one or the other only. Though this can happen if there is "-SNAPSHOT" in the <artifactId> in your project's POM.

另请参阅:

本文档的目标读者是Maven 2.0 alpha1.此处仅供历史参考,并进行更新和集成到Maven文档中.

This documentation was targetted at Maven 2.0 alpha 1. It is here only for historical reference and to be updated and integrated into the Maven documentation.

但是我到目前为止还没有找到任何最新的文档.

but I didn't find any latest documentation so far where this has been integrated.

了解Maven版本号.

这篇关于当本地和远程存储库中存在带有不同时间戳的SNAPSHOTS时,Maven如何解决SNAPSHOT依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆