Background:

In the daily development process, pull other people’s projects, or new projects to add dependencies in the POM file, many friends must have encountered the dependency download failure as shown in the following picture, I have encountered many times, here to sum up the solution, I hope to help you.





Reasons and solutions:

Configure Ali Cloud mirroring

Such download failure is generally caused by network conditions. The speed of accessing Maven central warehouse in China is relatively slow, which may lead to download failure. Therefore, we generally configure Ali Cloud image.

Add the ali cloud image to the tag setting. XML in the conf folder of maven:

<mirror>  
      <id>alimaven</id>  
      <name>aliyun maven</name>  
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
      <mirrorOf>*</mirrorOf>          
</mirror>
Copy the code

Even if we match the image of Ali Cloud, the dependency may still fail to download, so we can try the following solutions:

Manually delete dependencies that failed to download

First, we can find the failed dependency in the local repository, as shown in the figure below. The failed dependency is located in the path of my disk:

D: \ repository \ org \ springframework/boot/spring – the boot – starter ws-security \ 1.6.0

We can see that the file here ends with.lastupdated, which is the jar that failed to download. When the failed download file exists, reimport our POM. XML file, which will not re-download the failed JAR. Therefore, we need to manually delete these files that failed to download, and then reimport our POM. XML file to download again.

At this time, if the download still fails, we can try to switch to Using Ali Cloud image or not using Ali cloud image, maybe the download will be successful.

If you find it troublesome to manually delete the files that failed to download, you can use the following script:

@echo off
rem create by sunhao(sunhao.java@gmail.com)Rem Crazy coder REM put your repository path set REPOSITORY_PATH=D:\repository REM is searching...for /f "delims="% %i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do ( del /s /q %%i )Rem search completed pauseCopy the code

Do it like this:

  • Change to your own Maven repository path,
  • Then paste it in notepad and change the suffix to.bat,
  • Double-click the run to delete the failed JAR.

After deleting it, you can download it again. Click the red arrow to download it again.

Execute the repair incomplete dependency command

If you find that your dependencies don’t download automatically: Try the -u idea:idea command to fix incomplete dependencies





conclusion

Generally if it is a network problem caused by the download fails, then the above method to solve enough, another is maven central warehouse don’t have this dependence, such as Oracle, no, this time will certainly failed download, this needs the other methods, may need to change the warehouse, or manually the jar deployed to their warehouse, Specific steps can be baidu.