子模块依赖父模块后调用 maven 的 clean 命令报错问题求指点 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tiRolin
V2EX    Java

子模块依赖父模块后调用 maven 的 clean 命令报错问题求指点

  •  
  •   tiRolin 2024-09-29 22:31:14 +08:00 1596 次点击
    这是一个创建于 421 天前的主题,其中的信息可能已经有所发展或是发生改变。

    是这样的,我最近在做一个公司的练手 Demo 项目,顺便调试下环境,然而我子模块依赖父模块时却总是出问题,我的项目结构如下

    image-20240929222450448

    我想要实现的效果是 demo-parent 是 demo-project2 的子模块,demo-common 与 demo-server 是 demo-parent 的子模块

    我的步骤是先创建这些模块,然后指定他们的依赖关系,在指定 demo-parent 为 demo-project2 的子模块时没有出现问题

    然而在指定 demo-common 为 demo-parent 的子模块时却出现问题了,一旦在 demo-common 中的 pom 文件中写入如下代码

    <parent> <groupId>org.example.sun</groupId> <artifactId>demo-parent</artifactId> <version>1.0.0</version> <relativePath/> </parent> 

    此时对 demo-common 调用 maven 中的 clean 命令时会报下面的错误

    [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for org.example:demo-common:1.0.0: Could not transfer artifact com.example.sun:demo-parent:pom:1.0.0 from/to maven-snapshots ( http://localhost/repository/maven-snapshots/): Failed to transfer file: http://localhost/repository/maven-snapshots/com/example/sun/demo-parent/1.0.0/demo-parent-1.0.0.pom. Return code is: 400 , ReasonPhrase:Repository version policy: SNAPSHOT does not allow version: 1.0.0. and 'parent.relativePath' points at no local POM @ line 5, column 13 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project org.example:demo-common:1.0.0 (C:\Users\Iverson_xue\IdeaProjects\demo-project2\demo-common\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for org.example:demo-common:1.0.0: Could not transfer artifact com.example.sun:demo-parent:pom:1.0.0 from/to maven-snapshots ( http://localhost/repository/maven-snapshots/): Failed to transfer file: http://localhost/repository/maven-snapshots/com/example/sun/demo-parent/1.0.0/demo-parent-1.0.0.pom. Return code is: 400 , ReasonPhrase:Repository version policy: SNAPSHOT does not allow version: 1.0.0. and 'parent.relativePath' points at no local POM @ line 5, column 13 -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException 

    一旦注释掉这行代码,则不会报这个错误

    补充:由于这是公司的项目,因此上面的报错对可能暴露公司信息的内容做了修改,example 为公司的域名地址,而 localhost 则为公司的内网 ip 地址

    这个问题困扰了我好久了,我一直没能解决,我觉得我的做法并没有问题,我确定我已经在父模块中用 module 指定了子模块了,maven 地址也连接到了公司内网,jdk 也没错,什么都没问题然而每次只要一指定 demo-common 为 demo-parent 的子模块就会报上面的问题,我真的不知道该怎么解决这个问题了,所以我来问问各位,希望有大佬能救一救,小弟我先谢谢各位了

    2 条回复    2024-10-02 00:11:58 +08:00
    ikas
        1
    ikas  
       2024-09-29 22:46:43 +08:00
    <relativePath/>表示 从服务器下载 parent pom
    --
    <relativePath>../demo-parent/pom.xml</relativePath>
    tiRolin
        2
    tiRolin  
    OP
       2024-10-02 00:11:58 +08:00
    @ikas 你的解决方法完美解决了我的问题,感谢您的帮助!太谢谢你了
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3392 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 04:27 PVG 12:27 LAX 20:27 JFK 23:27
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86