简体   繁体   English

如何从父依赖 maven pom 文件中仅获取所需的依赖

[英]How to get only required dependency from parent dependency maven pom file

Can I include only the required dependencies from parent pom(like we have exclude)?我可以只包含来自父 pom 的必需依赖项(就像我们排除的那样)吗?

I need this to achieve one scenario我需要这个来实现一个场景

  1. Project A with hibernate and spring as my dependencies(there are many other)项目 A 与 hibernate 和 spring 作为我的依赖项(还有很多其他)
  2. Project B with only hibernate and spring项目 B 只有 hibernate 和 spring
  3. Project C with A and B as dependencies以 A 和 B 作为依赖项的项目 C

Problem statement : when I run maven install in project C, hibernate and spring are again downloaded separately.问题陈述:当我运行 maven 安装在项目 C 中时,hibernate 和 Z2A2D595E6ED2ED630B24D627 再次分别下载。 This I observed because of the increase in final jar size.这是我观察到的,因为最终 jar 大小增加了。

As a work around I included project A as dependency in project C so that I don't need to mention hibernate and spring explicitly.作为解决方法,我将项目 A 作为依赖项包含在项目 C 中,因此我不需要明确提及 hibernate 和 spring。

To avoid this is there a way to include only spring and hibernate from project A?为避免这种情况,有没有办法只包含项目 A 中的 spring 和 hibernate?

It sounds like you are guessing what's in the project C jar just based on size.听起来您只是根据大小猜测 C jar 项目中的内容。 Unzip the final jar (rename to.zip) and look inside to see what jars are actually being packaged to figure that out.解压缩最终的 jar(重命名为 .zip)并查看内部以查看 jars 实际打包的内容以弄清楚这一点。

Jars, wars, ears are just zip files with a manifest (more or less). Jars,战争,耳朵只是带有清单(或多或少)的 zip 文件。

So, your all dependencies should be defined in parent pom and all your projects here in case A, B and C should be child projects of the parent pom.因此,您的所有依赖项都应在parent pom中定义,并且您的所有项目都应在此处定义,以防 A、B 和 C 应该是父 pom 的子项目。

In all child poms, you can define all dependencies needed without versions, so that they will be resolved from parent pom.在所有子 pom 中,您可以定义所有需要的依赖项而不需要版本,以便从父 pom 解析它们。

Interdependency of child projects should be defined only in case of needed.仅在需要时才应定义子项目的相互依赖关系。 This, to get just dependencies from project A, C should not depends on A.为了从项目 A 中获取依赖项,C 不应该依赖于 A。

| - - A
| - - | - - pom.xml
| - - B
| - - | - - pom.xml
| - - C
| - - | - - pom.xml
| - - pom.xml (parent pom)

If you could get this structure as github project, then I can create a pull request with the changes.如果您可以将此结构作为 github 项目,那么我可以创建一个包含更改的拉取请求。

To Get Spring Hibernate from you need to make Child Parent relationship A(Parent) and B, C as Child.要从您那里获取 Spring Hibernate,您需要将 Child Parent 关系 A(Parent)和 B,C 作为 Child。

Jar file increment mustn't be the case. Jar 文件增量不能是这种情况。 POM.xml does provide reference of dependencies downloaded in.m2 repo. POM.xml 确实提供了在.m2 repo 中下载的依赖项的参考。

For further investigation we need POM.xml为了进一步调查,我们需要 POM.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM