首页 > 解决方案 > 父 pom 中的 Maven 子模块作为依赖项

问题描述

我正在尝试创建一个包含多个模块的 Maven spring-boot 项目。我创建了一个包装类型为pom的父模块和许多包装类型为jar的子模块。

所以我父母的pom.xml看起来像:

<groupId>Creator</groupId>
    <artifactId>DPAI</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>starter</module>
        <module>DatabaseApi</module>
        ...
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

子模块之一: starter 仅包含用 @SpringBootApplicatoion 注释的起始类,并且在其 pom.xml 中有一个包含其他子工件的部分,例如:

    <parent>
        <artifactId>DPAI</artifactId>        
        <groupId>Creator</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

<artifactId>starter</artifactId>
<packaging>jar</packaging>

 <dependencies>
        <dependency>
            <groupId>Creator</groupId>
            <artifactId>DatabaseApi</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
...
    </dependencies>

因此,我正在尝试进行一些重构并将 Main.class 和所有依赖项移动到我父母的 pom 中,但它不会因为我的依赖项引用自身的消息而出现错误。

在我看来,问题在于我的父 pom 包含带有它自己的子模块的部分。该子模块的父级是同一个 pom,我尝试在其中添加描述的依赖项

标签: javaspring-bootmaven

解决方案


parent.pom 不能包含任何 java 代码,只能包含 Maven 细节,例如参见:https ://howtodoinjava.com/maven/maven-parent-child-pom-example/#parent-content

也许告诉我们,你想要实现什么。


推荐阅读