简体   繁体   English

Maven依赖管理:传递与直接依赖

[英]Maven Dependency Management : Transitive Vs Direct Dependency

Consider a war application having following dependency. 考虑具有以下依赖性的战争应用。

War A --> Jar A --> jar B

War A adds dependency of Jar A only. 战争A仅添加对Jar A的依赖。 Gets jar B as transitive dependency. 获取jar B作为传递依赖。 But let's say something changes in B, then we need to build A with new version of B.Is this right thing to do? 但是,假设B中发生了一些变化,那么我们需要使用新版本的B构建A.这是对的吗? Every time B changes, A's pom needs to pick latest changes of B. Should War A specify direct dependency of A and B both or just A? 每次B更改时,A的pom都需要选择B的最新更改。战争A是否应指定A和B的直接依赖关系,还是仅指定A?

Is there some rule which says like we should ideally declare direct dependency of only those jar of which we are directly using the API of. 是否有一些规则说我们理想情况下应该声明仅直接使用其API的jar的直接依赖关系。

In above case, there is java class from jar B which is getting called from war A. 在以上情况下,jar B中有一个Java类,它是从war A中调用的。

Please help with my understanding. 请帮助我的理解。

In general, it's best to keep maven's convention, and allow it to resolve transitive dependencies, so you don't swirl into a dependency hell! 通常,最好保持maven的约定,并允许它解析可传递的依赖关系,因此您不会陷入依赖地狱!
If you want to test a change, you can, for testing purposes, add a direct dependency. 如果要测试更改,可以出于测试目的添加直接依赖项。

Keep it simple. 把事情简单化。 Allow maven to manage this. 允许Maven进行管理。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM