哪个jar最终出现在Maven增量构建的类路径上? [英] Which jar ends up on the classpath in a Maven incremental build?

查看:112
本文介绍了哪个jar最终出现在Maven增量构建的类路径上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的Maven澄清;我希望有经验的Maven开发人员可以轻松回答这个问题.

Simple Maven clarification; I hope this will be easy to answer from an experienced Maven developer.

我有两个名为mycompany-x和mycompany-y的项目. mycompany-x被列为mycompany-y的依赖项,并且每个都有1.0-SNAPHSOT版本.我们的Maven构建由连续构建服务器部署到内部Maven存储库中.每个快照都通过此服务器在开发人员之间共享.我们正在使用Maven 3.

I have two projects called mycompany-x and mycompany-y. mycompany-x is listed as a dependency of mycompany-y, and each has version 1.0-SNAPHSOT. Our Maven build is deployed to an internal Maven repository by a continuous build server. Snapshots of each are shared between developers via this server. We are using Maven 3.

在任何给定时间,当我运行mycompany-y的安装目标时,mycompany-x的存储库中可能有两个jar:一个标为1.0-SNAPSHOT的jar,这是本地构建的结果;第二个,标记为1.0-,从我们的Maven存储库作为解析下载到1.0-SNAPHSOT.当mycompany-y尝试解析mycompany-x的1.0-SNAPSHOT时,这会造成明显的歧义.我敢肯定,Maven社区有一项明确的政策可以解决(尽管在文档中尚不清楚).

At any given time, when I run the install goal of mycompany-y, there may be two jars in the repository for mycompany-x: one, labeled 1.0-SNAPSHOT, that is the result of a local build; the second, labeled 1.0-, downloaded as a resolution to the 1.0-SNAPHSOT from our Maven repository. This creates an obvious ambiguity when mycompany-y attempts to resolve 1.0-SNAPSHOT of mycompany-x; one which I am quite certain the Maven community has an explicit policy to resolve (although it is not clear in the docs).

在以下情况下,构建的类路径中包含哪个jar(本地或远程)?

In the following scenarios, which jar (local or remote) is included in the classpath of the build?

  1. 在mycompany-x和mycompany-y上运行mvn install.
  2. 无需先在mycompany-x上运行install即可在mycompany-y上运行mvn install.
  3. 最近在构建mycompany-x的同时,在mycompany-y上运行mvn install(并且在远程存储库中没有更高版本).
  4. 最近在构建mycompany-x的同时,在mycompany-y上运行mvn install(但在远程存储库中具有更新的版本).

注意:> Maven:如何为了确保在类路径中使用带有时间戳记的快照版本?引用了已发布的算法,我似乎在任何地方都找不到.我会接受那里的链接作为一个很好的答案.

Note: Maven: How to ensure timestamped versions of snapshots are used in classpath? references a published algorithm, which I can't seem to find anywhere. I would accept a link there as a fine answer.

推荐答案

以下是我在另一篇文章中提到的链接-

Here is the link I referred to in the other post - Maven Dependency Resolution - A Repository Perspective.

请注意,即使使用Maven中的3.0.x系列,此分辨率(不幸的是)也随着时间的推移而发生了变化.有关以下问题,请参见 Maven发行说明:

Note that this resolution (unfortunately) has shifted over time, even with the 3.0.x series in Maven. See the Maven release notes for the following issues:

[MNG-4987]-[回归]当解析顺序与时间戳顺序不匹配时,从错误的存储库中选择了最新,发布或快照版本 [MNG-4592]-由于通信问题而无法下载的快照工件默认情况下被黑名单"一天. [MNG-4751]-无法为版本范围解析快照版本

[MNG-4987] - [regression] LATEST, RELEASE or SNAPSHOT version picked from wrong repository when resolution order does not match timestamp order [MNG-4592] - Snapshot artifacts that could not be downloaded due to communication problems are "blacklisted" for a day by default. [MNG-4751] - Snapshot version not resolved for version range

SNAPSHOT分辨率的配置值也会影响事物.

这是另一张涉及SNAPSHOT的海报的示例

A,即使您弄清楚了,也必须向团队中的其他开发人员解释.

Alas, even if you figure it out, you have to explain it all to the rest of the devs on the team.

我们如何解决此问题:除了仅在CI上不使用SNAPSHOT依赖项之外,我们仅允许在CI上构建的项目声明固定的依赖项.我们使用 Maven版本插件只需单击一下即可制作发行版本(非SNAPSHOT).开发人员可以(并且应该)使SNAPSHOT在本地相互引用,但是将远程存储库完全保留在其中.

How we solved this: Instead of using SNAPSHOT dependencies on the CI, we only allow projects built on the CI to declare fixed dependencies. We use the Maven Release Plugin to make production of a release (non-SNAPSHOT) a single-click affair. Developers can (and should) have SNAPSHOTs referring to each other locally, but keep the remote repository completely out of it.

这篇关于哪个jar最终出现在Maven增量构建的类路径上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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