【发布时间】:2018-01-27 02:37:15
【问题描述】:
当我需要指定与父模块的子模块依赖关系时,我遇到了多模块 maven 项目的问题
这是我对 pom.xml 的配置
父 POM:
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>childA</module>
<module>childB</module>
</modules>
childA POM
<parent>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>childA</artifactId>
<dependencies>
<dependency>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
ChildB POM
<parent>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>childB</artifactId>
在 childB 中运行 mvn clean install 时,我能够构建 childB。
我在构建 Parent 和 ChildA 时遇到错误消息
ERROR] Failed to execute goal on project parent: Could not resolve dependencies for project com.parent:childA:jar:1.0-SNAPSHOT: Could not find artifact com.parent:parent:jar:1.0-SNAPSHOT -> [Help 1]
由于父包上有一些类,我需要在 childA pom.xml 中添加对父包的依赖项
我应该如何解决这个问题?
【问题讨论】:
-
首先注释掉所有
modulebuild only parent 然后取消注释并构建它会起作用。它通常会在你第一次做的时候发生。 -
依赖你的父母是没有意义的。您的父级是 pom 而不是工件(jar,war,...),因此您不能将任何子模块中的依赖项放在父级
-
这是这里唯一有效的答案!