通过在maven java项目中引用父级来拉取模块的依赖关系?

发布于 2024-10-01 21:15:49 字数 193 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋心╮凉 2024-10-08 21:15:49

这可以首先完成吗?

声明对聚合 POM 的依赖关系不会传递地获取模块。这是行不通的。可以将 POM 创建为 组依赖项

例如,EHCache就使用了这种技术。正如他们的文档中提到的:

Maven 片段

将 Ehcache 包含在您的项目中
使用:

 <依赖项>
       net.sf.ehcache;
       ehcache
       <版本>2.0.1
       <类型>pom
   

net.sf.ehcache:ehcache 工件精确地用于对依赖项进行分组(并且与 net.sf.ehcache:ehcache-parent 不同)。

指南

Can this be done in the first place?

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:

Maven Snippet

To include Ehcache in your project
use:

   <dependency>
       <groupId>net.sf.ehcache</groupId>
       <artifactId>ehcache</artifactId>
       <version>2.0.1</version>
       <type>pom</type>
   </dependency>

The net.sf.ehcache:ehcache artifact is precisely used to group dependencies (and is distinct from net.sf.ehcache:ehcache-parent).

References

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文