• Could not transfer artifact xxx from/to xxx解决方案


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

    Could not transfer artifact xxx from/to xxx
    方法一:
    这个问题主要就是在你下载相关的依赖包时,没有下载成功照成的,需要找到对应的maven库包,删除以 .lastUpdated 结尾的文件,然后重新下载,一般可以得到解决,

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


    import java.io.File;
    import java.io.IOException;

    //列出File的一些常用操作
    public class util {
    /**
    * 遍历指定目录下(包括其子目录)的所有文件,并删除以 lastUpdated 结尾的文件
    * @param dir 目录的位置 path
    * @throws IOException
    */
    public static void listDirectory(File dir) throws IOException {
    if (!dir.exists())
    throw new IllegalArgumentException("目录:" + dir + "不存在.");
    if (!dir.isDirectory()) {
    throw new IllegalArgumentException(dir + " 不是目录。");
    }
    File[] files = dir.listFiles();
    if (files != null && files.length > 0) {
    for (File file : files) {
    if (file.isDirectory())
    //递归
    listDirectory(file);
    else{ // 删除以 lastUpdated 结尾的文件
    String fileName = file.getName();
    boolean isLastupdated = fileName.toLowerCase().endsWith("lastupdated");
    if (isLastupdated){
    boolean is_delete = file.delete();
    System.out.println("删除的文件名 => " + file.getName() + " || 是否删除成功? ==> " + is_delete);
    }
    }
    }
    }
    }

    public static void main(String[] args) throws IOException {
    // 指定maven的本地仓库
    listDirectory(new File("D:\server\maven\repository"));
    }
    }
    方法二:
    按照方法一删除maven本地仓库中的以 lastUpdated 结尾的文件,然后将maven的配置文件中的仓库镜像改为阿里云或者其他国内进行地址,重新import一下。

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

    <mirror>
    <id>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>
    <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
    </mirror>
     

  • 相关阅读:
    剑指Offer面试题:26.字符串的排列
    剑指Offer面试题:25.二叉搜索树与双向链表
    使用VS2013分析DMP文件
    目的 存在 问题 价值
    thinking models--基于事实和全方位思考
    目的-哲学解释
    亚里士多德.四因说
    存在与目的 人类与上帝
    我用过的数据库 sqlite realm mysql coredata
    swift Existential Container witness table
  • 原文地址:https://www.cnblogs.com/shoshana-kong/p/14929863.html
Copyright © 2020-2023  润新知