spring-boot-maven-plugin 报红解决
问题描述:
本地编译打包maven项目时,报spring-boot-maven-plugin 构建找不到的错误。昨天还好好的,本地代码里的pom文件没有做任何改动。 pom.xml中有一段下面的配置:(已去掉项目信息)
<!--执行maven命令插件--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 报红 </plugin> </plugins> </build>
关键错误信息如下: spring-boot-maven-plugin jar包找不到。
分析:
- 去本地仓库,检查是否有该jar包
- 是否是maven配置的setting.xml文件镜像库路径有问题。
- 去远程仓库查看,检查是否有该版本的jar包
解决:
第一种情况:本地仓库有该jar包,但是在pom.xml文件中报红
通过分析:本地已下载好jar包,只是程序没有刷新找到。
如图点击刷新即可。
或者直接重启idea,再点击。亲测有效。
第二种情况:本地仓库有该jar包,但是setting.xml文件中maven镜像路径问题
添加镜像路径:
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <!--阿里云镜像1--> <mirror> <id>aliyunId</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>https://maven.aliyun.com/repository/central</url> </mirror> <!--阿里云镜像2--> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>https://maven.aliyun.com/nexus/content/groups/public/</url> </mirror> <!--阿里云镜像3--> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>https://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> <!--阿里云镜像4--> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>https://central.maven.org/maven2</url> </mirror> <!--maven官方镜像--> <mirror> <id>mirrorId</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name</name> <url>https://repol.maven.org/maven2/</url> </mirror> </mirrors>
第三种情况:本地仓库没有该jar包
spring-boot-maven-plugin没有设置version,它会先去远程仓库找最新的版本,然后download到本地,然后完成maven操作等。但是远程仓库里没有相应的jar包,导致执行maven编译出错。因为远程仓库里已经有了最新版本的路径,它就不会使用已经存在的版本。
解决:
给spring-boot-maven-plugin指定具体的version,如下设置:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.4.3</version> </plugin> </plugins> </build>
下一篇:
MySQL如何保存日期的问题