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

查看:112
本文介绍了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 clean安装时,我得到了一个失败,因为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天全站免登陆