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.
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 –
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 :end
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.
C:\M2\commons-beanutils\commons-beanutils\1.9.3 C:\M2\io\netty\netty-buffer\4.1.39.Final ... ... ... and so on
Drop me your question related to the maven corrupt local repository problem, and its solution provided above.
Happy Learning !!