Solve the problem of maven dependency import failure in projects opened by idea

Preliminary preparation

1. Set maven of idea

Step 1: modify the maven image address

Generally, after installing maven, the Maven image will be replaced by another image station, such as Alibaba cloud image. Because of the network, Maven images are often downloaded unsuccessfully. You can set the settings in the conf file under the Maven installation directory Add other image addresses in the mirrors node of the XML file. The specific image addresses are as follows:

	<mirrors>
		<!--Alicloud image-->
		<mirror>
		  <!-- Uniquely identify one mirror -->
		  <id>aliyun-maven-central</id>
		  <!-- Represents an alternate location for a mirror, for example central It means replacing the official central treasury -->
		  <mirrorOf>central</mirrorOf>
		  <!-- It doesn't seem to be of much use. It's equivalent to describing -->
		  <name>Human Readable Name for this Mirror.</name>
		  <!-- Is the official library address -->
		  <url>https://maven.aliyun.com/repository/central</url>
		</mirror>
	
		<mirror>
		  <id>aliyun-maven-jcenter</id>
		  <mirrorOf>jcenter</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/jcenter</url>
		</mirror>
		
		<mirror>
		  <id>aliyun-maven-public</id>
		  <mirrorOf>public</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/public</url>
		</mirror>
		
		<mirror>
		  <id>aliyun-maven-gradle-plugin</id>
		  <mirrorOf>gradle-plugin</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/gradle-plugin</url>
		</mirror>
		
		<mirror>
		  <id>aliyun-maven-spring</id>
		  <mirrorOf>spring</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/spring</url>
		</mirror>
		
		<mirror>
		  <id>aliyun-maven-spring-plugin</id>
		  <mirrorOf>spring-plugin</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/spring-plugin</url>
		</mirror>
		
		<mirror>
		  <id>aliyun-maven-grails-core</id>
		  <mirrorOf>grails-core</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/grails-core</url>
		</mirror>
		
		<mirror>
		  <id>aliyun-maven-apache-snapshots</id>
		  <mirrorOf>apache-snapshots</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/apache-snapshots</url>
		</mirror>
		
		<mirror>
		  <id>aliyun-maven-google</id>
		  <mirrorOf>google</mirrorOf>
		  <name>Human Readable Name for this Mirror.</name>
		  <url>https://maven.aliyun.com/repository/google</url>
		</mirror>
		
        <mirror> 
        	<id>repo2</id> 
            <mirrorOf>central</mirrorOf> 
            <name>spring2.0 for this Mirror.</name> 
            <url>https://repo.spring.io/libs-milestone</url> 
        </mirror> 
        <mirror> 
          <id>net-cn</id> 
          <mirrorOf>central</mirrorOf> 
          <name>Human Readable Name for this Mirror.</name> 
          <url>http://maven.net.cn/content/groups/public/</url>  
        </mirror> 
        <mirror> 
        	<id>ui</id> 
     		<mirrorOf>central</mirrorOf> 
            <name>Human Readable Name for this Mirror.</name> 
            <url>http://uk.maven.org/maven2/</url> 
        </mirror> 
        <mirror> 
        	<id>ibiblio</id> 
            <mirrorOf>central</mirrorOf> 
            <name>Human Readable Name for this Mirror.</name> 
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> 
        </mirror> 
        <mirror> 
        	<id>jboss-public-repository-group</id> 
            <mirrorOf>central</mirrorOf> 
            <name>JBoss Public Repository Group</name> 
            <url>http://repository.jboss.org/nexus/content/groups/public</url> 
        </mirror>
    </mirrors>

At the top are most of the image addresses. Add them according to the situation. Generally, Alibaba cloud images are enough.

Step 2: update

After completing the first two steps, perform the following operations.

At this time, the idea will download the dependency to the modified image address, which is better because the modified image address download dependency is successful. But it usually doesn't go so well.

Step 3: delete the dependency that failed to download

Because the dependency download fails, there are often more dependencies in the local warehouse lastUpdated is a file with a suffix. Locate these files and delete them.

Step 4: repeat steps 1 to 3

To put it bluntly, it means frequently modifying settings Download dependencies based on the image address in the XML file, and constantly switch the download source (you can switch between the official image and the alicloud image, and you can try many image addresses provided in step 1). Before each image switch, delete the dependencies that failed to download. Repeat steps 1 to 3 until successful.

In the first three steps, 99% of the cases can be solved by telling the truth, but if you can't tell too much, there will still be accidents.

Contingency

This is the case with me. No matter how I switch the image address, I can't download it by relying on it. What I get is forever lastUpdated is a file with a suffix. At this time, you can only download it manually on the Internet. Generally, it is downloaded pom file. If a pom file fails to be downloaded, the following dependent files cannot be downloaded.

Spring-boot-starter-2.3.9 RELEASE. pom. Lastupdated as an example, how to download it on the Internet?

Alicloud image

Maven image




Put the downloaded file in the corresponding directory in the local warehouse, and you will find that the dependency can be downloaded normally again. Repeat the previous three steps.

‚Äč

Tags: Java Maven intellij-idea

Posted by alapimba on Thu, 02 Jun 2022 11:22:09 +0530