Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们有一个父 POM,我们想在其中设置一个依赖项,但没有该依赖项的版本。这个想法有点像抽象成员:我们要确保继承者指定此依赖项的特定实例。
如何最好地实现这一目标?我们可以在父级中设置一个默认版本,如果子级想要覆盖它,那么他们可以使用dependencyManagement. 另一种可能的解决方案是使用在子项中设置的属性。
dependencyManagement
如果在 中定义依赖项<dependencies>,则必须设置(有效)版本号。但是,正如您所说,您可以将版本号放入属性中。然后,如果需要,子项目可以覆盖此属性。但是,父项目有一个默认版本。
<dependencies>
<dependenyManagement>只是用来声明依赖关系。但它不会向您的项目添加依赖项。
<dependenyManagement>