我是新的使用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。在jenkins中,我读过git中两个不同maven项目中的父pom和子pom。我想从父POM继承所有的依赖项和插件。有可能吗?
6条答案
按热度按时间moiiocjp1#
您应该在
<dependencies>
节下声明要继承的依赖项以实现此目的。<dependencyManagement>
用于以后必须在需要时在特定子级的<dependencies>
中引用才能生效的定义。UPDATE:声明每个子pom都将继承的依赖时要小心。很快,你就可以结束拥有你并不真正需要的依赖项,仅仅因为它们是在父级中声明的。正如其他评论者所提到的,
<dependencyManagement>
可能是一个更好的选择,尽管它不是您最初想要的。zsbz8rwp2#
事实上,你有两种方法来处理这个问题。
1.您可以在
<dependencyManagement />
节点下的父pom和每个需要它的子pom中分解依赖项,在<dependencies />
节点中添加依赖项。您可以选择不设置依赖项的版本。1.或者在
<dependencies />
节点的父pom中声明依赖关系,每个子节点都将受益于依赖关系。例如,如果你在父pom中声明:
字符串
那么
slf4j-api
将是所有子节点的依赖项。但是,您必须在子对象的pom中添加对slf4j-simple
的依赖,如果它需要它:型
对于插件,它的工作原理相同,但使用
<pluginManagement />
和<plugins />
节点。所有的配置都可以放在父pom的插件定义中,你只需在子pom的<build />
部分声明插件。ff29svar3#
下面是如何使用父和子pom的示例。
父pom如下:
字符串
如果您在
dependencyManagement
标记中指定了一个依赖项,它仅仅意味着您正在使这个jar可用于子pom。它将不实际上在这一点上下载jar。子pom必须显式地提供groupId
和artifactId
,以便下载和使用jar来编译它的类。注意:您不必在子pom中包含依赖的版本。子pom将如下所示:
型
将所有查尔兹对象共有的依赖项放在父pom的
dependencyManagement
标记中是一个很好的做法。通过这种方式,您可以从一个地方管理这些依赖项的版本。xriantvc4#
父pom.xml
字符串
子pom.xml
的数据
xuo3flqw5#
在
<dependencyManagement>
中添加的内容将自动添加到孩子的pom中。唯一需要注意的是,在子模块的pom中,我们不需要显式地添加版本,否则这将是其他仅适用于子模块的依赖项。parent_pom.xml
字符串
child_pom.xml
型
jmo0nnb36#
除了其他回复之外,我想在这里补充一些关于依赖声明的总结要点。有两个部分与依赖关系有关,
所以父节点和子节点都可以有这两个部分,
*parent.dependencymanagement:一个依赖项的列表(用版本号来表示),所有子项目都可以引用它,但不需要提到版本号,只需要提到组和工件ID
*parent.dependency:所有子项目自动继承的依赖项列表(可用于常见依赖项,如junit)
*child.dependencymanagement:可以由其子项目(如果有)引用的依赖项列表(未提及版本)
*child.dependency:此子模块附带的依赖项列表