• 无法解析 Failure to transfer *** from *** was cached in the local repository


    问题描述:

    在进行创建maven工程自动导入对应的依赖或者执行 mvn install 时提示如下的错误信息:

    Could not transfer artifact xxx from/to xxx
    无法解析 Failure to transfer *** from *** was cached in the local repository, resolution will not be reattempted until the update interval of alimaven has elapsed or updates are forced. Original error: Could not transfer artifact ***from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public/): Connection reset
    1. /**
    2. * @Author: shenxinbo
    3. * @Date: 2023/11/17 10:48
    4. * @Package: PACKAGE_NAME
    5. */
    6. import java.io.File;
    7. import java.io.IOException;
    8. //列出File的一些常用操作
    9. public class util {
    10. /**
    11. * 遍历指定目录下(包括其子目录)的所有文件,并删除以 lastUpdated 结尾的文件
    12. * @param dir 目录的位置 path
    13. * @throws IOException
    14. */
    15. public static void listDirectory(File dir) throws IOException {
    16. if (!dir.exists())
    17. throw new IllegalArgumentException("目录:" + dir + "不存在.");
    18. if (!dir.isDirectory()) {
    19. throw new IllegalArgumentException(dir + " 不是目录。");
    20. }
    21. File[] files = dir.listFiles();
    22. if (files != null && files.length > 0) {
    23. for (File file : files) {
    24. if (file.isDirectory())
    25. //递归
    26. listDirectory(file);
    27. else{ // 删除以 lastUpdated 结尾的文件
    28. String fileName = file.getName();
    29. boolean isLastupdated = fileName.toLowerCase().endsWith("lastupdated");
    30. if (isLastupdated){
    31. boolean is_delete = file.delete();
    32. System.out.println("删除的文件名 => " + file.getName() + " || 是否删除成功? ==> " + is_delete);
    33. }
    34. }
    35. }
    36. }
    37. }
    38. public static void main(String[] args) throws IOException {
    39. // 指定maven的本地仓库
    40. listDirectory(new File("D:\\ideaMaven\\MavenRepository"));
    41. }
    42. }

    Step1:

    这个问题主要就是在你下载相关的依赖包时,没有下载成功照成的,需要找到对应的maven库包,删除以 .lastUpdated 结尾的文件,然后重新下载,一般可以得到解决,如图所示

    这里有一个脚本,删除maven本地仓库以 .lastUpdated 结尾的文件

    1. /**
    2. * @Date: 2023/11/17 10:48
    3. */
    4. import java.io.File;
    5. import java.io.IOException;
    6. //列出File的一些常用操作
    7. public class util {
    8. /**
    9. * 遍历指定目录下(包括其子目录)的所有文件,并删除以 lastUpdated 结尾的文件
    10. * @param dir 目录的位置 path
    11. * @throws IOException
    12. */
    13. public static void listDirectory(File dir) throws IOException {
    14. if (!dir.exists())
    15. throw new IllegalArgumentException("目录:" + dir + "不存在.");
    16. if (!dir.isDirectory()) {
    17. throw new IllegalArgumentException(dir + " 不是目录。");
    18. }
    19. File[] files = dir.listFiles();
    20. if (files != null && files.length > 0) {
    21. for (File file : files) {
    22. if (file.isDirectory())
    23. //递归
    24. listDirectory(file);
    25. else{ // 删除以 lastUpdated 结尾的文件
    26. String fileName = file.getName();
    27. boolean isLastupdated = fileName.toLowerCase().endsWith("lastupdated");
    28. if (isLastupdated){
    29. boolean is_delete = file.delete();
    30. System.out.println("删除的文件名 => " + file.getName() + " || 是否删除成功? ==> " + is_delete);
    31. }
    32. }
    33. }
    34. }
    35. }
    36. public static void main(String[] args) throws IOException {
    37. // 指定maven的本地仓库
    38. listDirectory(new File("D:\\ideaMaven\\MavenRepository"));
    39. }
    40. }

    Step2:

    按照方法一删除maven本地仓库中的以 lastUpdated 结尾的文件,然后将maven的配置文件中的仓库镜像改为阿里云或者其他国内进行地址,重新import一下。

    比如下面的镜像,在setting.xml中的mirrors中添加阿里云镜像

    1. <mirror>
    2. <id>alimavenid>
    3. <mirrorOf>centralmirrorOf>
    4. <name>aliyun mavenname>
    5. <url>http://maven.aliyun.com/nexus/content/repositories/central/url>
    6. mirror>
    7. <mirror>
    8. <id>alimavenid>
    9. <name>aliyun mavenname>
    10. <url>http://maven.aliyun.com/nexus/content/groups/public/url>
    11. <mirrorOf>centralmirrorOf>
    12. mirror>

     

    Step3:

    重新加载pom.xml

  • 相关阅读:
    EasyRecovery2023互盾免费数据恢复软件下载功能介绍
    安装Frida工具
    主要开源WebGIS介绍、自由及开源GIS软件、组件产品
    windows10中docker与vm不兼容
    星球作业(第十期)Android中的ClassLoader
    dom转换原生js对象
    Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图
    设计数据库
    【Python】Scrapy 环境搭建
    [附源码]JAVA毕业设计列车票务信息管理系统(系统+LW)
  • 原文地址:https://blog.csdn.net/intmain_S/article/details/134460819