看这篇文章之前先试试这个方法,如果不管用再看下面的方法
解决方案
将父项目install
到本地仓库,重新对子项目进行打包
报错情景
父项目需要用到子项目,会将子项目加入POM的依赖
比如:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tonited</groupId>
<artifactId>hello-spring-cloud-alibaba-dependencies</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
子项目打包时会报错
比如:
The build could not read 1 project -> [Help 1]
The project com.tonited:hello-spring-cloud-alibaba-provider:0.0.1-SNAPSHOT (C:\Users\Tonited\Desktop\hello-spring-cloud-alibaba\hello-spring-cloud-alibaba-provider\pom.xml) has 3 errors
Non-resolvable import POM: Could not find artifact com.tonited:hello-spring-cloud-alibaba-dependencies:pom:0.0.1-SNAPSHOT in aliyunmaven (https://maven.aliyun.com/nexus/content/groups/public) @ com.tonited:hello-spring-cloud-alibaba:0.0.1-SNAPSHOT, C:\Users\Tonited\Desktop\hello-spring-cloud-alibaba\pom.xml, line 43, column 25 -> [Help 2]
‘dependencies.dependency.version’ for org.springframework.cloud:spring-cloud-starter-alibaba-nacos-discovery:jar is missing. @ line 45, column 21
‘dependencies.dependency.version’ for org.springframework.cloud:spring-cloud-starter-alibaba-nacos-config:jar is missing. @ line 50, column 21
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
原因
其实是因为子项目打包需要依赖父项目,但是在检查本地仓库时发现仓库中并没有父项目,于是就会去仓库找
仓库当然没有你的父项目,就会报错