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.
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 extension – ".lastUpdated"
.
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
3. Usage
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 !!
This is BS. All the artifact folders have a “.lastUpdated”-file – not just the corrupted ones. Effectively, this advice is the same as deleting the whole .m2-directory.
These files indicate to Maven that it attempted to obtain the archive by download, but was unsuccessful. In order to save bandwidth, it will not attempt this again until a certain time period encoded in the file has elapsed. Read More
after capturing the file list , what is the correction that i have to take to make my maven build work perfect
The script deletes the jars and put in the list for your information. Run the Maven build again and it should run fine.