Learn to rebuild local repository by deleting all corrupt jars from repository and fix missing or corrupt maven dependencies problem.
This solution will help you in situations where you want to force update a maven project or want to 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 extension –
In this solution, we have created a windows batch file (please write similar script for mac/linux systems) which does the following:
- Find all folders which contain any file with extension ‘.lastUpdated’.
- Remove the folder and it’s content – forcefully.
- Log the folder location for reference.
2. Batch file to delete maven corrupt jars
Below is the batch file which performs all steps listed in 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 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 file (list of deleted corrupt dependencies) in a file.
$ delete-corrupt-dependencies.bat > files.txt
After above batch file completes processing – you may check the list of missing maven dependencies, which just got cleaned up, into files.txt file generated in 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 maven corrupt local repository problem and it’s solution provided above.
Happy Learning !!