是这样的,我最近在做一个公司的练手 Demo 项目,顺便调试下环境,然而我子模块依赖父模块时却总是出问题,我的项目结构如下
我想要实现的效果是 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 的子模块就会报上面的问题,我真的不知道该怎么解决这个问题了,所以我来问问各位,希望有大佬能救一救,小弟我先谢谢各位了
1
ikas 62 天前
<relativePath/>表示 从服务器下载 parent pom
-- <relativePath>../demo-parent/pom.xml</relativePath> |