Maven – Remove All Corrupt Jars

Lokesh Gupta

Learn to rebuild the local repository by deleting all corrupt jars from the repository and fixing missing or corrupt maven dependencies problems.

This solution will help you when you want to force update a maven project or download missing maven dependencies.

1. Approach

In maven, you will observe that most dependencies get corrupted because to interrupted downloading of jars. This interruption leaves behind a special file with an extension – ".lastUpdated".

In this solution, we have created a windows batch file (please write a similar script for mac/Linux systems) that does the following:

  • Find all folders which contain any file with the extension ‘.lastUpdated’.
  • Remove the folder, and its content – forcefully.
  • Log the folder location for reference.

2. Batch File to Search and Delete All Corrupt Jars

Below is the batch file which performs all steps listed in the above section.

:: Usage
:: C:/M2> delete-corrupt-dependencies.bat > files.txt

@echo off
setlocal EnableDelayedExpansion
set last=?

for /f %%I in ('dir /s /b /o:n /a-d "*.lastUpdated"') do (
  if !last! NEQ %%~dpI (
    set last=%%~dpI
    echo !last!
    rd /s /q !last!
goto end


3. Demo

Place the above windows batch file in maven’s M2 folder.

Now open the command prompt and run the batch file. You may capture the output of a file (list of deleted corrupt dependencies) in a file.

$ delete-corrupt-dependencies.bat > files.txt

After the above batch file completes processing – you may check the list of missing maven dependencies, which just got cleaned up, into the files.txt file generated in the current directory.

and so on

Drop me your question related to the maven corrupt local repository problem, and its solution provided above.

Happy Learning !!


Notify of
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode