当前位置: 首页 > 面试题库 >

如何从父pom继承依赖关系到子pom

郭修平
2023-03-14
问题内容

我是使用Maven和Jenkins的新手。我试图继承从父pom到子pom的依赖关系,它显示以下错误:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/XMLConverters.java:[10,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/XMLConverters.java:[11,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/XMLConverters.java:[15,38] cannot find symbol
  symbol:   class AbstractRequestMessageData_Type
  location: class com.td.inv.wss.util.XMLConverters
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/XMLConverters.java:[26,23] cannot find symbol
  symbol:   class AbstractResponseMessageData_Type
  location: class com.td.inv.wss.util.XMLConverters
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/UsTermRateItemComparator.java:[5,42] package com.rpmtec.current.UsTermRate_Type does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/UsTermRateItemComparator.java:[7,61] cannot find symbol
  symbol: class UsTermRateItems
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/UsTermRateItemComparator.java:[9,28] cannot find symbol
  symbol:   class UsTermRateItems
  location: class com.td.inv.wss.util.UsTermRateItemComparator
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/UsTermRateItemComparator.java:[9,48] cannot find symbol
  symbol:   class UsTermRateItems
  location: class com.td.inv.wss.util.UsTermRateItemComparator
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[9,40] package com.fasterxml.jackson.annotation does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[10,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[11,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[12,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[13,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[14,42] package com.rpmtec.current.UsTermRate_Type does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[19,2] cannot find symbol
  symbol: class JsonIgnoreProperties
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[69,22] cannot find symbol
  symbol:   class ORCA_GETTERMHOLDINGRS_Type
  location: class com.td.inv.model.COIRQ
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[69,66] cannot find symbol
  symbol:   class RPM_GETPLANACCOUNTOVERVIEWRS_Type
  location: class com.td.inv.model.COIRQ
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/model/COIRQ.java:[70,25] cannot find symbol
  symbol:   class ORCA_GETTERMINSTRUCTIONRS_Type
  location: class com.td.inv.model.COIRQ
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[5,26] package javax.ws.rs.client does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[6,26] package javax.ws.rs.client does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[7,26] package javax.ws.rs.client does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[8,26] package javax.ws.rs.client does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[9,24] package javax.ws.rs.core does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[15,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[16,26] package com.rpmtec.current does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[23,57] cannot find symbol
  symbol:   class AbstractRequestMessageData_Type
  location: class com.td.inv.wss.util.RPMInvoker
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/util/RPMInvoker.java:[24,41] cannot find symbol
  symbol:   class AbstractResponseMessageData_Type
  location: class com.td.inv.wss.util.RPMInvoker
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/application/InvestmentAPI.java:[4,19] package javax.ws.rs does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/application/InvestmentAPI.java:[5,24] package javax.ws.rs.core does not exist
[ERROR] /D:/jenkins/workspace/CBAW/testP/WSW_Investment/src/main/java/com/td/inv/wss/application/InvestmentAPI.java:[9,36] cannot find symbol
  symbol: class Application

这是我的父母POM:

.....
<modelVersion>4.0.0</modelVersion>
<groupId>group1</groupId>
<artifactId>group1-artifact</artifactId>
<version>1.0.1</version>
<packaging>pom</packaging>

<modules>
     <module>child1</module>
</modules>
.......

这是我的孩子POM:

.....
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>group1</groupId>
    <artifactId>group1-artifact</artifactId>
    <version>1.0.1</version>
    <relativePath>(full url.....)/jenkins-parent-pom//pom.xml</relativePath>
</parent>
<groupId>group1</groupId>
<artifactId>child1</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
......

这是我尝试从父POM继承子POM中的依赖项的方法

<dependencyManagement>  
  <dependencies>
    <dependency>
      <groupId>group1</groupId>
      <artifactId>group1-artifact</artifactId>
      <version>1.0.1</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

如果我将相同的依赖项放在子POM中,则效果很好。我使用jenkins在nexus中clean install进行安装和deploy部署。我正在使用maven-3.3.9。在詹金斯,我从git中阅读了两个不同的Maven项目中的父项和子项。我想从父POM继承所有依赖项和插件。可能吗?


问题答案:

您应该在<dependencies>要实现这一点的部分下声明要继承的依赖项。<dependencyManagement>用于定义,以后必须在<dependencies>特定子对象中引用该定义,以使其生效。

更新
声明每个子pom都将继承的依赖项时要小心。很快,您就可以拥有真正不需要的依赖项,因为它们是在父级中声明的。正如其他评论者所提到的<dependencyManagement>,虽然这并不是您最初想要的,但也许是一个更好的选择。



 类似资料:
  • 我是使用maven和jenkins的新手。我正在尝试从父pom继承到子pom的依赖关系,它显示以下错误: 这是我的父母POM: 这是我的孩子波姆: 这是我如何尝试从父POM继承子POM中的依赖关系: 如果我在子POM中放置这些相同的依赖项,它会完美地工作。我使用jenkins在nexus中进行安装和部署。我使用的是maven-3.3.9。在jenkins中,我阅读了git中两个不同maven项目中

  • 在我的父pom xml文件中,我声明了一些在大多数孩子的pom中使用的依赖项。 然而,在一个子pom中,我不使用这些依赖项,我想找到一种方法来排除它们(为了不被视为未使用的依赖项)。 现在,在子pom的依赖部分,我什么都没有!有什么想法吗?

  • 我在父pom中有一个版本为2.3的Jackson,在我的子pom中我需要版本2.9,是否有任何方法排除父pom依赖?

  • 我有一个maven工件(),它依赖于某个工件()。 有一个父pom,其中包含某些其他依赖项。 是否可以使用这些依赖项,而无需在其自身pom的依赖项部分中明确添加它们?

  • 我试图理解从根pom文件到中级pom文件的继承指令。说明书上写着: 定义父pom文件继承和groupid、artifactid(但不是版本),从中间级父级到根pom文件。