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

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

问题描述

我的设置是这样的.我有项目 A,以及一个依赖于 A 的测试项目:

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

A <- A_t

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

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

A <- B <- B_t

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

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

A <- Atesthelper

所以 A_t(和 B_t)将依赖于这个测试助手,像这样:

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

A <- A_t
^    |
|    v
Atesthelper

但是,当我创建 Maven 项目 (pom.xml) 时,通常的做法是将项目和该项目的测试捆绑在同一个 pom.xml 中.我为 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

所以现在变成了:

(A <- A_t)
  ^    |
  |    v
Atesthelper

这是一个循环依赖.是否可以在 pom.xml 中以某种方式指定 Atesthelper 只是测试构建目标的依赖项,而不是 A 模块本身?

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?

所以构建顺序应该是:A、Atesthelper、A_t.IE.A 和 A_t 在同一个 pom 中指定,不能同时构建.

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.

提前致谢.

推荐答案

你需要解决的问题是 AtesthelperA 的依赖,那么其他的一切都会工作正常:A 依赖于 AtesthelperB 依赖于 Atesthelper 和两者 AB 将包含源和测试.Atesthelper 将包含在 AB 中的范围 test 中.那是你的目标状态.

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.

你怎么去那里?您需要将 Atesthelper 所依赖的项目提取到单独的项目中.通常,这些是接口或其他通用功能,无论如何都应该将其放入单独的项目中 - 我们称之为 ACommon.所以你的目标布局应该是这样的:

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)

Atesthelper 依赖于 A 中的哪些功能?你能把它移到一个单独的项目(ACommon)吗?

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

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

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