Maven:我应该保留还是删除声明的依赖项,这些依赖项也是传递依赖项?
您认为删除 Maven pom 中可以找到的所有传递依赖项是一个好习惯吗?
示例:
我的项目取决于 A 和 B。
B 也是 A 的传递依赖。
我应该将 B 保留在我的 pom 中还是将其删除?
什么是最好的:
拥有所有已知的 jar,甚至是传递性的 jar,在 pom 上声明还是只保留顶级 jar?
这有点主观,但我正在尝试清理一些具有大量传递依赖项的巨大 poms(父级和子级)。我想让我的 pom 尽可能简单,但我也希望它们是可维护的。
Do you think it is a good practice to remove every transitive dependencies that can be found in a maven pom?
Example:
My project depends on A and B.
B is also a transitive dependency of A.
Should I keep B in my pom or remove it ?
What is the best:
having all known jars, even transitive one, declared on the pom or keeping only the top level jars ?
This is a little bit subjective, but I am trying to clean some huge poms (parent and children) with a lot of transitive dependencies. I want to keep my pom as simple as possible, but I want also them to be maintainable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的项目对 B 具有直接依赖关系,那么即使 B 是 A 的传递依赖关系,您也应该保留它。在下一个版本中,A 可能不会使用 B,您将不得不重构 pom.xml。
一般来说,Maven 依赖关系应该反映逻辑项目依赖关系。
If your project has direct dependencies on B then you should keep it even if B is a transitive dependency of A. It can be that in the next version A won't use B an you'll have to restructure the pom.xml.
Generally, Maven dependencies should reflect the logical project dependencies.
我更愿意避免声明传递依赖项,并在有充分理由的情况下将它们显式包含在 pom 中。以下是我的论点:
通过声明传递依赖项(即使您明确需要它们):
引入了声明中的冗余,因为此信息已经存在于所需工件的 pom 描述符中< /em>.
如果新版本的所需工件不再依赖于
传递依赖
,则必须从您的传递依赖
中删除传递依赖
如果显式声明了传递依赖项
,请自行组装。通过显式声明传递依赖来操纵传递性信息。
在以下情况下显式包含依赖项是有意义的:
C
和D
,它们需要不同的版本传递依赖项B
(或者您需要在项目中使用特定版本的B
)。在这种情况下,您必须选择B
的版本并显式定义传递依赖项T
。 (*)结论:
我会尽量避免声明,除非专门声明工件是有意义的(如 (*) 的情况)。
I would prefer to avoid the declaration of the transitive dependencies, and explicitly include them in the pom if there is a good reason for that. Here are my arguments:
By declaring the transitive dependencies (even if you explicitly need them):
Redundancy in the declaration is introduced, because this information is already in the pom descriptor of the artifact that is required.
If a new version of the artifact required does not depend on the
transitive dependency
anymore, you have to remove thetransitive dependency
from your assembly yourself, if thattransitive dependency
is explicitly declared.The information for the transitivity gets manipulated by declaring the transitive dependency explicitly.
It would make sense to include a dependency explicitly in the following case:
C
andD
, that require different versions of the transitive dependencyB
(or you require a specific version ofB
in your project). In this case you have to choose a version ofB
and explicitly define the transitive dependencyT
. (*)Conclusion:
I would try to avoid the declaration, unless it makes sense to declare the artifact specifically (like in the case (*)).