解决测试,测试和测试项目之间的Maven循环依赖关系 [英] Resolving Maven circular dependencies between test, testhelper, and project-under-test

查看:617
本文介绍了解决测试,测试和测试项目之间的Maven循环依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的设置。我有项目 A ,根据 A 的测试项目:

  A<  -  A_t 

我也有其他项目取决于 A (及其测试):

  A< ;  -  B<  -  B_t 

为了简化一些测试,我引入了一个帮助测试的新库基于 A

  A<  -  Atesthelper 

所以 A_t (和 B_t )将依赖于此测试助手,如下所示:

  A<  -  A_t 
^ |
| v
Atesthelper

然而,当我创建Maven项目(pom.xml)时,事情是将该项目的项目和测试捆绑在同一个pom.xml中。而且我为 Atesthelper创建一个新的pom.xml



所以现在变成:

 (A<  -  A_t)
^ |
| v
Atesthelper

哪个是循环依赖。在pom.xml中有可能以某种方式指定 Atesthelper 只是测试构建目标的依赖关系,而不是 A 模块本身?



所以构建顺序应该是:A,Atesthelper,A_t。即A和A_t在同一个pom中指定,不应该同时生成。



提前感谢

解决方案

您需要解决的问题是从 Atesthelper A 的依赖关系,那么其他一切都可以正常工作: A 取决于Atesthelper , B 取决于Atesthelper 和 A > B 将同时包含源和测试。在 A B 中,Atesthelper 将包含在范围测试中。这是你的目标状态。



你如何到达那里?您需要将Atesthelper 的项目提取到单独的项目中。通常,这些是接口或其他常见功能,应该放在单独的项目中 - 我们称之为ACommon 。所以您的目标布局应该如下所示:

  ACommon<  -  Atesthelper 
^ ^
| /
A(还有B)

什么样的功能是Atesthelper 取决于 A ?你可以把它移动到一个单独的项目( ACommon )?


my set up is this. I have project A, and a test project depending on A:

A <- A_t

I also have other projects depending on A (and their tests):

A <- B <- B_t

To simplify some of the testing I introduce a new library helping test stuff based on A:

A <- Atesthelper

So A_t (and B_t) will depend on this test helper, like this:

A <- A_t
^    |
|    v
Atesthelper

However when I create Maven projects (pom.xml) it seems the usual thing is to bundle both the project and the test of that project in the same pom.xml. And I create a new pom.xml for the Atesthelper

So now it becomes:

(A <- A_t)
  ^    |
  |    v
Atesthelper

Which is a circular dependency. Is it possible in the pom.xml to somehow specify that Atesthelper is only a dependency of the test build target, and not the A module in itself?

So the build order should be: A, Atesthelper, A_t. I.e. A and A_t which are specified in the same pom, should not be build at the same time.

Thanks in advance.

解决方案

The problem that you need to solve is the dependency from Atesthelper to A, then everything else will work fine: A depends on Atesthelper, B depends on Atesthelper and both A and B will contain both sources and tests. Atesthelper will be included with scope test in both A and B. That's your target state.

How do you get there? You need to extract the items that Atesthelper is depending on into a separate projects. Typically, these are interfaces or other common functionality, which should be put into a separate project anyway - let's call it ACommon. So your target layout should look like this:

ACommon <- Atesthelper
       ^    ^
       |   /
         A (and also B)

What kind of functionality is Atesthelper depending on in A? Can you move it to a separate project (ACommon)?

这篇关于解决测试,测试和测试项目之间的Maven循环依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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