Ele*_*aar 11 dependencies maven multi-module
我没有找到任何东西就搜索过这样的问题,所以我走了.
我有一个多模块maven项目.多个模块都继承相同的父模块,其中定义了公共依赖项.其中,有一个我自己的模块,一个'通用'模块,其中实现了一些常用功能.
我的问题是:对于公共依赖项,什么是更好的做法:在父级中明确地定义它们,就像我现在一样?或者在"公共"模块中定义它们,其他模块引用它们,然后依赖于传递性(如公共依赖项的单入口点)?
Cap*_*aps 16
最好使用父pom中的dependencyManagement标记来定义依赖项及其版本,然后在需要的子模块中引用这些依赖项.当您需要项目中的其他子模块(即来自另一个子模块的公共子模块)时,将依次发现依赖关系.例如:
在你的父母pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
在你的普通pom中(注意没有版本或范围):
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
然后你可以从其他子模块中引用你的常见子模块.
| 归档时间: |
|
| 查看次数: |
12624 次 |
| 最近记录: |