【发布时间】:2021-07-04 22:05:33
【问题描述】:
我有一个多模块化应用程序,
我需要从父模块导入一些类(它们对于所有模块都是相似的)
因此,正如 intellij 提示的那样,我对父模块建立了依赖关系
(这是我的第一个多模块应用程序)
问题是当我这样做时
mvn clean install -Dmaven.test.skip=true
构建失败。
看来maven正在从在线依赖中寻找我的父项目,显然它不存在,它应该在本地查找......我认为
实际上应用程序可以构建和运行,但我无法制作包,我无法安装它...
我该如何解决?
这是一些代码:
父级的 pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>eu.mrndesign.matned</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>../credit</module>
<module>../client</module>
<module>../product</module>
</modules>
<name>parent</name>
<description>Description</description>
<packaging>pom</packaging>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${project.parent.version}</version>
</plugin>
</plugins>
</build>
</project>
其中一个孩子 pom(他们 3 岁,看起来几乎一样):
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>eu.mrndesign.matned</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<parent>
<groupId>eu.mrndesign.matned</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>product</artifactId>
<name>product</name>
<description>Product module for create credit application</description>
<properties>
<java.version>11</java.version>
</properties>
这是全新安装时的消息:
[INFO] ---------------------< eu.mrndesign.matned:credit >---------------------
[INFO] Building credit 1.0-SNAPSHOT [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for parent 1.0-SNAPSHOT:
[INFO]
[INFO] parent ............................................. SUCCESS [ 0.857 s]
[INFO] credit ............................................. FAILURE [ 0.133 s]
[INFO] client ............................................. SKIPPED
[INFO] product ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.237 s
[INFO] Finished at: 2021-04-09T03:53:09+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project credit: Could not resolve dependencies for project eu.mrndesign.matned:credit:jar:1.0-SNAPSHOT: Failure to find eu.mrndesign.matned:parent:jar:1.0-SNAPSHOT in https://repo.spring.io/release was cached in the local repository, resolution will not be reattempted until the update interval of spring-releases has elapsed or updates are forced -> [Help 1]
[ERROR]
【问题讨论】:
-
当你有多模块项目时,父 pom 将有
packaging类型为pom。这意味着它不会生成任何工件,因此您不能将其用作依赖项。有一些方法可以通过使用插件等来解决它,但一般的 maven 方法是在父项目中没有任何代码,它应该用于定义模块、依赖管理、公共依赖和插件配置等。 -
谢谢Setu,你是对的。我已经完成了另一个模块,将课程移到了那里。现在它工作正常
标签: spring maven multi-module