当前位置: 首页 > news >正文

maven本地仓库清缓存py脚本

清_remote.repositories、以及 .lastUpdated 缓存文件,避免换仓库or私服的时候一直往旧地方去download从而引起的failtodownlown问题

import os
import sysdef delete_maven_metadata_files(directory):"""递归删除指定目录下的 _remote.repositories 和 .lastUpdated 文件:param directory: 要扫描的目录(如 Maven 本地仓库路径)"""deleted_files = {"_remote.repositories": 0, ".lastUpdated": 0}for root, _, files in os.walk(directory):for file in files:file_path = os.path.join(root, file)# 匹配 _remote.repositories 或以 .lastUpdated 结尾的文件if file == "_remote.repositories" or file.endswith(".lastUpdated"):try:os.remove(file_path)key = ".lastUpdated" if file.endswith(".lastUpdated") else filedeleted_files[key] += 1print(f"已删除: {file_path}")except Exception as e:print(f"删除失败 [{file_path}]: {e}")print("\n删除完成统计:")for file_type, count in deleted_files.items():print(f"{file_type}: {count} 个")if __name__ == "__main__":# 硬编码目标目录(修改为你需要的路径)target_dir = os.path.expanduser("D:\\dev\\maven-repository2")if not os.path.isdir(target_dir):print(f"错误: 目录不存在 [{target_dir}]")sys.exit(1)print(f"开始清理目录: {target_dir}")delete_maven_metadata_files(target_dir)
http://www.dtcms.com/a/284017.html

相关文章:

  • 设计模式笔记_结构型_装饰器模式
  • centos中新增硬盘挂载文件夹
  • Install Docker Engine on UbuntuMySQL
  • 【安卓按键精灵辅助工具】adb调试工具连接安卓模拟器异常处理
  • Vuex中store
  • 爬虫核心原理与入门技巧分析
  • JavaScript中的Window对象
  • Vue3入门-组件及组件化
  • Sentinel配置Nacos持久化
  • Python爬虫实战:研究cssutils库相关技术
  • AI问答-供应链管理:各种交通运输方式货运成本分析
  • 如何用文思助手改好一篇烂材料
  • maven(配置)
  • clonezilla 导出自动化恢复iso
  • 信息安全基础专业面试知识点(上:密码学与软件安全)
  • 解锁 iOS 按键精灵辅助工具自动化新可能:iOSElement.Click 让元素交互更简单
  • springmvc跨域解决方案
  • RAG实战指南 Day 18:Chroma、Milvus与Pinecone实战对比
  • 基于springboot+vue+mysql框架的工作流程管理系统的设计与实现(源码+论文+PPT答辩)
  • 23种设计模式--#2单例模式
  • 从AWS MySQL数据库下载备份到S3的完整解决方案
  • ros2 标定相机
  • 企业级网络综合集成实践:VLAN、Trunk、STP、路由协议(OSPF/RIP)、PPP、服务管理(TELNET/FTP)与安全(ACL)
  • CKS认证 | Day6 监控、审计和运行时安全 sysdig、falco、审计日志
  • Redis主从复制数据同步实现原理详细介绍
  • UML用例规范,use case diagram
  • 灵易智模中的重构导出可以做什么
  • Jmeter使用 -1
  • c++项目从aws服务器转移到mac编译
  • Spring Boot 自动配置:从 spring.factories 到 AutoConfiguration.imports 的演变