问题
依赖导入不成功,一直标红

idea控制台报错显示
Cannot resolve Failure to transfer org.springframework.boot:spring-boot-starter-jdbc:pom:2.0.2.RELEASE from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-starter-jdbc:pom:2.0.2.RELEASE from/to central (https://repo.maven.apache.org/maven2): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
解决方案
强制更新依赖,打开电脑终端,进入项目根目录,在项目根目录执行:
mvn clean install -U
之后依赖成功下载导入成功
问题原因分析
- Maven本地仓库缓存问题
-
Maven会将下载的依赖缓存到本地仓库(
/repository) -
当第一次下载失败时,Maven会缓存这个"失败状态"
-
即使网络恢复正常,Maven仍然会使用缓存的失败状态,不会重新尝试下载
2.mvn clean install -U 的作用
clean
-
删除项目的
target目录 -
清理之前编译生成的文件
install
-
编译项目代码
-
运行测试
-
将项目打包并安装到本地仓库
-U
-
强制检查所有依赖的更新
-
忽略本地缓存的失败状态
-
重新尝试下载所有依赖
-
强制Maven与远程仓库重新同步