maven仓库中的LastUpdated文件生成原因及删除

maven仓库中的LastUpdated文件生成原因及删除


    在使用idea离线导入maven仓库的时候总是提示jar文件导入不成功的错误,后经过分析,发现不成功的文件夹里面存在lastUpdate后缀名的文件,删除该文件也未曾生效,依然会重新生成,后经过分析_remote.repositories文件,发现如下的情况

junit-3.8.1.pom>nexus=
junit-3.8.1.jar>nexus=
junit-3.8.1.jar>central=
junit-3.8.1.pom>central=
    maven的setting.xml配置如下

<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<name>nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
    通过我测试发现,我设置aliyun仓库的时候,会更新_remote.repositories为如下内容

junit-3.8.1.pom>nexus=
junit-3.8.1.jar>nexus=
    如果我将aliyun仓库注释掉,默认使用外网maven仓库,此时_remote.repositories为如下内容

junit-3.8.1.pom>nexus=
junit-3.8.1.jar>nexus=
junit-3.8.1.jar>central=
junit-3.8.1.pom>central=
    原来每次在更新maven项目的时候,每一个jar包路径下的_remote.repositories文件都会同setting.xml中设置的仓库地址id进行判断,如果没有匹配,会自动更新该jar包的相关文件,如果未联网则会出现jar无法发现的错误,导致即使jar存在,maven项目也无法使用该jar的情况。如果使用公司的内网仓库,_remote.repositories文件变为_maven.repositories。

    最后,附上删除lastupdated脚本文件

    1、cleanLastUpdated.bat(windows版本)

@echo off
rem create by NettQun

rem 这里写你的仓库路径
set REPOSITORY_PATH=D:\Java\maven-repository\maven-aliyun\repository
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
echo %%i
del /s /q "%%i"
)
rem 搜索完毕
pause

 


    2、cleanLastUpdated.sh(linux版本)

# create by NettQun

# 这里写你的仓库路径
REPOSITORY_PATH=~/Documents/tools/repository
echo 正在搜索...
find $REPOSITORY_PATH -name "*lastUpdated*" | xargs rm -fr
echo 搜索完

 

posted @ 2021-04-28 09:12  zhangzl419  阅读(1067)  评论(0编辑  收藏  举报