知识卡片

普通读书笔记卡 · 3383

直接使用的依赖应显式声明

理解等级:中级

代码直接导入某个库时,应在自己的依赖清单中显式声明它;仅凭上游库碰巧传递带入,未来上游调整依赖就可能使构建或运行失败。反射等动态使用还需专门测试。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Principles of Software Architecture Modernization》第4章《Anti-Patterns: Internal Shared Libraries》(源文件:`_epub-src/OPS/ch04.xhtml`,归一化正文 [79659:83838)) - 结论依据:原文明确告诫不能直接依赖未声明的传递依赖,提供方改变依赖图即可破坏消费者。 - 原始内容:Explicitly declare dependencies Dependencies have dependencies; but dependencies of dependencies can always change. You should not depend directly on a transitive dependency without explicitly declaring in your pom.xml. It only takes one change from the library provider to break your code, whether internal or external. In order to be more resilient, only depend on dependencies explicitly declared in your pom.xml .