Maven 和依赖模块 [英] Maven and dependent modules

查看:27
本文介绍了Maven 和依赖模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同事们一直在吹捧 maven 的奇迹及其神奇的依赖关系,但我发现它在我认为明显的用途方面失败了.

Colleagues have been touting the wonders of maven and its magical dependency stuff but I'm finding that it fails at what I would consider the obvious use.

假设我有一个包含主 POM 的根文件夹.

Suppose I have a root folder with a master POM.

然后在下面我有一些项目,称它们为 A 和 B

Then underneath I have some projects, call them A and B

B 需要 A,因此 B 文件夹中的 POM 中有相应的依赖项

B requires A and so the POM in the B folder has the appropriate dependency entry in it

现在,回到根文件夹,在一个配置文件中,我指定我要构建 B.

Now, back in the root folder, in a profile, I specify that I want to build B.

当我执行通常的 mvn 全新安装时,我失败了,因为 A 没有构建.

When I perform the usual mvn clean install, I get a failure because A was not built.

我的朋友告诉我,我必须在根目录的主配置文件中同时指定 A 和 B.

My friends tell me I have to specify both A and B in that main profile in the root.

但是 maven 看到 B 并不是依赖管理的全部意义,而是转到 B POM 文件,在那里它看到对 A 的依赖,因此它应该自动构建 A.

But isn't the whole point of dependency management that maven sees B, goes to the B POM file where it sees the dependency on A and so it should go build A automatically.

推荐答案

我能想到的你想要的行为没有实现的原因如下:

A reason I can think of that your desired behaviour hasn't been implemented is as follows:

假设我正在处理项目 A 和 B.目前 A 已损坏.如果依赖解析如你所愿,在 A 被修复之前,我将永远无法构建 B.所以我要么必须回滚我对 A 的更改,要么首先专注于修复 A.无论哪种方式,可能都不是我现在想要关注的.

Suppose I'm working on both projects A and B. Currently A is broken. If dependency resolution happened as you would like, I would never be able to build B until A was fixed. So I either have to roll back my changes to A, or focus on fixing A first. Either way possibly not what I want to focus on right now.

通常 B 想要使用 A 的最后一个好"版本,而不是最新版本.使用存储库中的依赖项意味着它们至少可以正常编译(希望单元测试也能运行).

Generally B wants to work with the "last good" version of A, rather than the latest. Using the dependencies from the repository means they at least compiled ok (and hopefully the unit tests were run too).

这篇关于Maven 和依赖模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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