Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inherit dependency from a parent pom to a child pom

I am new in using maven and jenkins. I am trying to inherit the dependencies from parent pom to child pom it shows the following errors:

[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 

Here is my parent 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> ....... 

Here is my child 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> ...... 

Here is how I tried to inherit dependency in child POM from parent 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> 

If I put those same dependencies in the child POM, it works perfectly. I do clean install for installing and deploy for deploying in nexus by using jenkins. I am using maven-3.3.9. In jenkins, I have read the parent and child poms in two different maven projects from git. I want to inherit all the dependencies and plugins from parent POM. Is it possible?

like image 830
Cherry Avatar asked Aug 10 '16 19:08

Cherry


People also ask

How do you get dependency from parent pom?

Now child POM need to refer the parent POM using parent tag and specifying groupId/artifactId/version attributes. This pom file will inherit all properties and dependencies from parent POM and additionally can include extra sub-project specific dependencies as well.

What is inherited from parent pom?

When a project specifies a parent project, Maven uses that parent POM as a starting point before it reads the current project's POM. It inherits everything, including the groupId and version number.

How do I override a parent pom?

It sounds like A version 2.5 is being included transitively by another dependency. This puts both version 4.3 and 2.5 at the same length. By explicitly defining dependency of A 2.5 in your project it will then be the nearest and override any other versions.

How is relative path used in pom xml?

The relative path, if not given explicitly, defaults to .. , i.e. the pom in the parent directory of the current project. So Maven checks whether a) there is a pom file in that directory and b) that pom file contains the same coordinates as stated in the parent definition of the current project.


1 Answers

You should declare dependencies you want to inherit under a <dependencies> section to achieve this. <dependencyManagement> is used for definitions that must be referenced later, whenever needed, within the <dependencies> of a particular child to become effective.

UPDATE: Be careful when declaring dependencies that every child pom will inherit. Very quickly you can end up having dependencies you don't really need just because they are declared in the parent. As mentioned by other commenters, <dependencyManagement> may be a better choice, although it isn't what you wanted originally.

like image 159
vempo Avatar answered Oct 15 '22 04:10

vempo