通过在maven java项目中引用父级来拉取模块的依赖关系?
我有一个 maven-java 项目(比如项目 A),其父级在其 pom.xml 中定义模块。 我还有一个外部项目(例如项目 B),需要项目 A 中的两个模块的依赖项。目前,我已经定义了单独拉取每个模块的依赖项。 当我用对父 pom 的依赖替换这两个时,它在构建时出错。我是否需要对项目 A 的父 pom 进行一些修改才能使其工作?
首先可以做到这一点吗?
I have a maven-java project (say Project A) with a parent defining modules in its pom.
I also have an external project (say Project B) that requires dependencies of two of the modules from Project A. For now, i have defined the dependency to pull each module individually.
When i replace these two with a dependency on the parent pom, it errors out on build. Is there some modification i need to make to my parent pom of Project A to make this work?
Can this be done in the first place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
声明对聚合 POM 的依赖关系不会传递地获取模块。这是行不通的。可以将 POM 创建为 组依赖项。
例如,EHCache就使用了这种技术。正如他们的文档中提到的:
net.sf.ehcache:ehcache
工件精确地用于对依赖项进行分组(并且与net.sf.ehcache:ehcache-parent
不同)。指南
Declaring a dependency on an aggregating POM won't get the modules transitively. This is not going to work. It is possible to create a POM to group dependencies though.
For example, EHCache uses this technique. As mentioned in their documentation:
The
net.sf.ehcache:ehcache
artifact is precisely used to group dependencies (and is distinct fromnet.sf.ehcache:ehcache-parent
).References