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 @   zhangzl419  阅读(1256)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示