Solve the problem that IDEA Maven dependency download fails, and Maven dependency package import fails to report red (project practice)

When importing a maven project to IDEA, there are some dependencies that cannot be downloaded. I tried my best and checked all the information, but I still couldn't solve it. Finally, I solved the problem through a whim of mine.

1. My pom file reports red dependencies, which can be found on the official website of the maven warehouse, but no matter what method I think of, IDEA just can’t download the dependencies

2. First, list the solutions collected on the Internet to solve maven dependencies that cannot be downloaded (I have tried all these methods, but they cannot solve my problem)

(1) Network problems. The domestic network of maven's official warehouse is relatively slow. If you use the Alibaba Cloud warehouse, you can go to the official website of the Alibaba Cloud maven warehouse to view the maven configuration guide: warehouse service (my maven configuration is the latest official one)

(2) The lastUpdated file causes the dependencies to fail to import normally, delete the lastUpdated related files, and re-refresh the imported dependencies (my local maven warehouse does not even report red dependent related files)

(3) Click the button to re-import Maven dependencies multiple times

 (4) Delete or comment out all the dependencies corresponding to the pom file or the place where the MavenProject on the right reports red, perform maven refresh, then withdraw the deletion and perform maven refresh again

(5) Click the maven-related function keys in the upper right corner, first click the first arrow to reload all maven projects (the problem has not been solved), click the second arrow to download all resources and documents (the problem still cannot be solved)

 (6) Click the offline mode by mistake. If you click the offline mode and click again to refresh maven again, the picture below is what it looks like before clicking the offline mode

 The picture below is what it looks like after clicking the offline mode

 (7) Modify maven's settings.xml file, re-create a new local maven warehouse, and re-download all maven dependencies in a place with a better network

(8) The maven version and the idea version may not be compatible, open the maven settings of the idea, you can use the maven version recommended by the idea

 Bundled (Maven3) in the picture is the maven that comes with idea, and Version3.8.1 in the brackets below is the specific version of maven it uses, but it still can't solve my problem

(9) Manually execute the maven command in IDEA, click the button below (Execute Maven Goal)

 Always enter -U idea:idea on the command line to fix incomplete dependencies, and press Enter to execute

3. In the end, I solved the problem of pom.xml reporting red through two methods

(1) Since the maven official warehouse can search for this dependency, I can manually download it directly from the official warehouse, and then install it locally. You can read this blogger's article and manually install maven dependencies into your own maven warehouse . Manually download dependencies - Learning Java Blog - CSDN Blog

There is a problem, if there are many dependencies reported by the pom, it will be cumbersome to manually install so many dependencies

(2) I created a simple maven project, you can create it yourself, it should be simple enough, the picture below is my project directory

 I copied all the dependencies reported in the previous project to the pom file of this project, and then clicked maven to refresh and import dependencies. At this time, maven actually downloaded all the dependencies reported in the pom to the local warehouse, and then I added them to the previous maven project. Refresh the maven import in the middle, the pom file red all disappears, the problem is solved

​​​​​​​

4. Why copy the relevant dependencies to a simple maven project and download it, but in the original maven project, it just doesn’t download it?

 I checked the information on the Internet and felt that the jar package referenced by maven may have a version conflict, or other imported dependency packages already contain the dependencies reported in the pom file. Idea thinks that there is no need to download these dependencies (these dependencies are redundant) , the red report is because the local warehouse does not have these dependencies, but the red report may not affect the startup and operation of the project

So I annotated all the dependencies that were reported before, and then started the project, successfully started

I uncommented, deleted the relevant dependencies in the local warehouse, and returned to the original state. The local warehouse did not have these dependent pom files and reported red. I started the project again, and the project still ran successfully.

Note: The above is my process of dealing with maven's inability to download dependencies in IDEA. I hope it can help you

Guess you like

Origin blog.csdn.net/qq_41928263/article/details/130743278