Maven下载依赖失败解决方案

本文解决因settings.xml配置不当导致Maven依赖下载失败的问题,介绍正确的配置方法及如何删除.lastUpdated文件,确保依赖更新。

本文主要解决settings.xml文件配置的不对导致的下载依赖不成功只能下载lastUpdate文件问题。
setting.xml

<?xml version="1.0" encoding="UTF-8"?>      
<settings   xmlns="http://maven.apache.org/POM/4.0.0"    
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">          
    <!--本地仓库。该值表示构建系统本地仓库的路径。其默认值为${user.home}/.m2/repository。  -->  
     <localRepository>C:\Users\LENOVO\.m2\repository</localRepository>        
    <!--Maven是否需要和用户交互以获得输入。如果Maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。 -->  
    <interactiveMode>true</interactiveMode>  
    <!--Maven是否需要使用plugin-registry.xml文件来管理插件版本。  -->  
    <!--如果设置为true,则在{user.home}/.m2下需要有一个plugin-registry.xml来对plugin的版本进行管理  -->  
    <!--默认为false。 -->  
    <usePluginRegistry>false</usePluginRegistry>  
    <!--表示Maven是否需要在离线模式下运行。如果构建系统需要在离线模式下运行,则为true,默认为false。  -->  
    <!--当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。  -->  
    <offline>false</offline>  
    <profiles>
    <profile>    
      <id>jdk-1.8</id>    
       <activation>    
          <activeByDefault>true</activeByDefault>    
          <jdk>1.8</jdk>    
        </activation>    
      <properties>    
      <maven.compiler.source>1.8</maven.compiler.source>    
      <maven.compiler.target>1.8</maven.compiler.target>    
      <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
      </properties>    
    </profile>    
    </profiles>
    <mirrors>  
    <!-- 阿里代理镜像地址 -->
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
    </mirrors>  
</settings> 

重新下载依赖前要讲仓库中对应的.lastUpdated文件删除。
运行下面的批处理文件可以批量删除仓库中的.lastUpdated文件
clearLastUpdated.bat

@echo off
rem create by NettQun  
rem 这里写你的仓库路径
set REPOSITORY_PATH=C:\Users\LENOVO\.m2\repository
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
    echo %%i
    del /s /q "%%i"
)
rem 搜索完毕
pause

删除后重新下载依赖就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值