2017-05-30 221 views
0

在我的多模块maven项目中,所有模块都依赖于我自己的“common”模块,例如,模块“A”具有此依赖性“common ”。而“通用”模块具有spring-boot-starter-test依赖关系。但是,当我在此“A”模块中编写单元测试时,它显示未导入测试依赖项。然后我检查依赖关系,发现没有导入spring-boot-starter-test。我想问为什么?在我的意义上,模块“A”参考“常见”,“常见”参考spring-boot-starter-test,所以模块“A”应参考spring-boot-starter-test,但事实并非如此。顺便说一句,尽管这个spring-boot-starter-test其他依赖通过hirachy很好地工作。有谁知道它为什么?先谢谢你。依赖项spring-boot-starter-test未在多个模块中继承maven项目

+0

为什么因为范围是'test',所以只包含编译时间和非可选依赖项。 –

+0

哦......谢谢你的信息 – Yun

回答

2

最有可能在模块“A”依赖spring-boot-starter-test有范围test。这种范围的相关性不是传递性的。请参阅依赖关系范围部分https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html。 最好的解决方案是依赖管理。见依赖管理

简单地说,你需要创建parrent模块,并声明依赖同治sectoin:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>A</artifactId> 
      <version>1.0</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

然后继承父的模块和刚刚宣布的依赖,而不versionscope

<dependencies> 
     <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>A</artifactId> 
     </dependency> 
    </dependencies> 
+0

谢谢。这似乎是我没有足够的maven知识 – Yun

相关问题