You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven多模块项目构建报错:无法找到父模块Artifact问题排查

问题原因

你遇到的错误是因为父模块archive_service的打包类型是pom,但子模块tfs的依赖里没指定该依赖的类型,Maven默认会去寻找jar类型的com.example:archive_service:1.0-SNAPSHOT,自然找不到。

另外,多模块项目中,子模块已经通过<parent>标签继承了父模块的所有配置(包括依赖、编译属性等),完全没必要再在子模块的<dependencies>里显式依赖父模块,这属于冗余配置,也是触发错误的直接原因。

修复方案

方案一:移除子模块中不必要的父模块依赖(推荐)

修改tfs模块的pom.xml,删除<dependencies>里针对archive_service的依赖段:

<project >
    <parent>
        <artifactId>archive_service</artifactId>
        <groupId>com.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.tfs</groupId>
    <artifactId>tfs</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <!-- 移除这段冗余依赖 -->
    <!-- <dependencies>
       <dependency>
           <groupId>com.example</groupId>
           <artifactId>archive_service</artifactId>
           <version>1.0-SNAPSHOT</version>
       </dependency>
   </dependencies> -->

</project>

方案二:若确实需要依赖父模块(不推荐,无必要场景)

如果因特殊需求必须依赖父模块,需在依赖中指定<type>pom</type>,告诉Maven这是一个pom类型的构件:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>archive_service</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>pom</type> <!-- 新增该行指定类型 -->
</dependency>
验证修复

修改完成后,回到项目根目录(archive_service文件夹下),重新执行:

mvn clean install

即可正常完成构建。

内容的提问来源于stack exchange,提问作者Jelly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 17:37:17