我可以避免一个边缘是测试依赖的依赖循环吗? [英] Can I avoid a dependency cycle with one edge being a test dependency?

查看:169
本文介绍了我可以避免一个边缘是测试依赖的依赖循环吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个 testCycle 父模块 DummyCore TestFramework

TestFramework 取决于 DummyCore DummyCore TestFramework 上有测试dedepency。

TestFramework depends on DummyCore, and DummyCore has a test dedepency on TestFramework.

独立构建和测试每个模块maven没有问题。但是 mvn test 父母 testCycle 会导致:

Building and testing each module independently maven has no problems. But mvn test the parents testCycle results in:

    The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.mysimpatico:TestFramework:1.0-SNAPSHOT'}' and 'Vertex{label='org.apache:DummyCore:1.0-SNAPSHOT'}' introduces to cycle in the graph org.apache:DummyCore:1.0-SNAPSHOT --> com.mysimpatico:TestFramework:1.0-SNAPSHOT --> org.apache:DummyCore:1.0-SNAPSHOT -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectCycleException

重现:

wget http://dp4j.sf.net/debug/testCycle.zip
unzip testCycle.zip
cd testCycle; mvn test 

我的期望是maven将构建 DummyCore src然后来编译测试将编译 TestFramework src,它不依赖于 DummyCore 。在这个阶段,它将编译 DummyCore src + tests,以及 TestFramework src。最后它还将编译 DummyCore 测试。有没有办法告诉maven这样做?
如果没有,你会如何解决这个问题?

My expectation was that maven would build DummyCore src and then coming to compile the tests will compile TestFramework src, which doesn't depend on DummyCore. At this stage it would have compiled DummyCore src + tests, and TestFramework src. Finally it will compile DummyCore tests too. Is there a way to tell maven to do this? If not, how would you work around this?

DummyCore 中的测试移动到模块中它本身取决于 DummyCore TestFramework ?我只是为了满足maven。

Move the tests in DummyCore into a module of its own that depends on DummyCore and TestFramework? I'd be doing that just to satisfy maven.

推荐答案

你无法解决与Maven或任何其他构建的这种冲突工具。这不是构建工具问题,它是一个架构缺陷,只能通过重构来解决。

You can't resolve this conflict with Maven or with any other build tool. It's not a build tool issue, it is an architectural flaw and can only be addressed through refactoring.

立即想到两个选项:

1)创建一个名为test_common的新模块,其中包含这些内容TestFramework需要和DummyCore都需要。 make test_common是这两个模块的依赖关系。

1) Create a new module called "test_common" that contains the stuff that both TestFramework need and DummyCore need. The make test_common a dependency of both of those modules.

2)将TestFramework需要的东西从DummyCore移动到TestFramework中。然后,TestFramework不依赖于任何东西,DummyCore依赖于TestFramework。

2) Move the stuff that TestFramework needs from DummyCore into TestFramework. Then TestFramework depends on nothing and DummyCore depends on TestFramework.

有很多方法可以解决这个问题,但是循环模块间依赖关系是一个非常重要的时间,无论语言如何或构建工具。

There are many ways to solve this, but circular inter-module dependencies are a big time NO-NO regardless of language or build tool.

这篇关于我可以避免一个边缘是测试依赖的依赖循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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