因为relativePath导致项目内依赖失败

其实我之前研究过<relativePath/>,这个标签貌似是说从库中去寻找依赖,但是我当时理解的并不是很深入,知道我今天踩了这个坑。

我项目结构如下:


parent:
  sub
    pom.xml
  pom.xml

我在sum目录写了如下的<parent>

1
2
3
4
5
6
7
8

<parent>
    <groupId>com.sdstc</groupId>
    <artifactId>srm</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath/>
</parent>

结果无法执行mvn clean指令,报如下错误:


[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.sdstc:srm-common:1.0-SNAPSHOT: Failure to find com.sdstc:srm:pom:1.0-SNAPSHOT in http://192.168.20.9:8081/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of maven-public has elapsed or updates are forced 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 com.sdstc:srm-common:1.0-SNAPSHOT (C:\Users\wujj\Desktop\projects\srm\srm-common\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.sdstc:srm-common:1.0-SNAPSHOT: Failure to find com.sdstc:srm:pom:1.0-SNAPSHOT in http://192.168.20.9:8081/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of maven-public has elapsed or updates are forced 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

Process finished with exit code 1

去掉<relativePath/>后恢复正常。