Should I rely on transitive dependencies in Maven if they come from other sub-module of my parent?

前端 未结 3 1963
半阙折子戏
半阙折子戏 2021-01-19 16:41

Suppose we are working on mortgage sub-module, and we are directly using the Google Guava classes in module code, but the dependcy for the

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-19 17:33

    When a module uses a 3rd party library, the module should explicitly depend on that library in its pom.xml too. Imagine if another project should use the 'mortgage' module, and doesn't depend on Guava already, it will fail e.g. when a unit test comes upon a code path that involves Guava. An explicit dependency also covers you against the scenario where you refactor the 'investment' module so that it doesn't use Guava anymore. Your 'investment' module should be agnostic to such changes in its dependencies.

    It's always correct to explicitly list your direct dependencies. When it comes to version, it's best to keep that in the dependencyManagement section of your parent pom so all child projects inherit that (same) version.

提交回复
热议问题