【问题标题】:Maven - multi module application - problem with clean installMaven - 多模块应用程序 - 全新安装问题
【发布时间】: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


【解决方案1】:

您需要从子模块中删除父依赖声明。父标记已经足以指定该模块是父模块的一部分

<modelVersion>4.0.0</modelVersion>
<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>

【讨论】:

  • 但是没有它我不能使用父类的类,不是吗?
  • 如果您想使用其他模块,您可以直接将这些模块添加到依赖项中。如果您想使用所有可用的类,则无需将其分解为多个模块。
【解决方案2】:

父级不能包含代码,因此不能用作依赖项。

将你的类放入一个模块中,并使用该模块作为其他模块的依赖项。

【讨论】:

  • 非常感谢,这就是我想听到的 :) 现在它工作正常 :)
猜你喜欢
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多