Inheritance 我是否可以避免一个边缘为测试依赖项的依赖循环?
考虑一个带有模块Inheritance 我是否可以避免一个边缘为测试依赖项的依赖循环?,inheritance,maven,dependency-management,circular-dependency,pom.xml,Inheritance,Maven,Dependency Management,Circular Dependency,Pom.xml,考虑一个带有模块DummyCore和TestFramework的testCycle父级 TestFramework依赖于DummyCore,并且DummyCore对TestFramework具有测试依赖性 独立构建和测试每个模块maven没有问题。但是mvn测试父母testCycle导致: The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.mysimpatico:
DummyCore
和TestFramework
的testCycle
父级
TestFramework
依赖于DummyCore
,并且DummyCore
对TestFramework
具有测试依赖性
独立构建和测试每个模块maven没有问题。但是mvn测试
父母testCycle
导致:
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+测试和TestFramework
src。最后,它还将编译DummyCore
测试。有没有办法告诉maven这样做?
如果没有,你将如何解决这个问题
将
DummyCore
中的tests
移动到依赖于DummyCore
和TestFramework
的模块中?我这样做只是为了满足maven。你不能用maven或任何其他构建工具解决这个冲突。这不是一个构建工具问题,而是一个架构缺陷,只能通过以下方式解决
我马上想到两个选择:
1) 创建一个名为“test_common”的新模块,其中包含TestFramework和DummyCore都需要的内容。使测试单元成为这两个模块的共同依赖项
2) 将TestFramework需要的东西从DummyCore移动到TestFramework中。然后TestFramework不依赖于任何东西,DummyCore依赖于TestFramework
有很多方法可以解决这个问题,但不管是语言还是构建工具,循环模块间依赖关系都是一个大问题。但是我同意cyle依赖关系是一个糟糕的设计,有一种情况我仍然试图创建一个,这正是OP所要求的:测试。 我有基于我的模型的DSL测试类,这使我能够编写类似
Book Book=新书()
assertThat(book.hasnoauther();//“hasnoauther()”是AssertJ基断言
验证(book,never()).addAuthor(anyAuthor());//“anyAuthor()”是基于mockito的匹配器
这些DSL对象既可用于测试我的图书对象所在的域
模块,也可用于测试使用我的域
模块的其他模块
因此,我尝试创建一个域测试
模块以及现有的域
模块,但是
中的单元测试取决于域
DSL类域测试
域测试中的DSL类取决于
域
域
模块中提取单元测试:
域单元测试
>取决于>域
+域测试
域测试
>取决于域
在分离的maven模块中分离代码和测试对我来说非常糟糕。也许我应该成长或者我应该改变我的工具
解决方案
将所有内容保持在同一个maven模块中,但只使用DSL类创建一个“测试jar”
需要2件事
org.apache.maven.plugins
)根据我的经验,到目前为止还没有得到解决,循环依赖总是大声说设计有问题。不管循环是在jar、包还是类中,这都是构建工具的问题。我解释了一个更聪明的Maven是如何避免依赖循环的。不,这是一个设计缺陷。任何依赖于这两个模块的代码都需要存在于它自己的模块中。你满意的不是maven,而是依赖关系图,这是一个构建工具的问题。在实际层面上,您希望在同一个模块中进行模块测试,但是它在逻辑上是独立的,并且没有理由无法编译。事实上,Gradle可以处理这种情况。