Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

preface

In the daily development process, when pulling other people’s projects, or adding dependencies to poM files for new projects, many friends must have encountered the dependency download is slow or failure.

In today’s episode, we will cover some tips for setting up Maven in IDEA. After you learn how to set up Maven, you will never have to worry about the slow downloading of Maven dependencies.

Maven Settings

If we do not modify the Setting file in Maven after downloading and installing Maven. The default is to access the Maven central warehouse, while the speed of accessing the Maven central warehouse in China is relatively slow, which may cause download failure. Therefore, we generally configure Ali Cloud image.

The Maven default convention address is used in IDEA. By default, it reads setting.xml from under the system user.m2 folder. And add the image of Ali Cloud in the tag of setting. XML:

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

Then go back to IDEA and download the dependency again, and you’ll find it much faster.

Default Settings for new projects

There is a problem, however, that the Maven setting is only valid for the current project.

Some people may put setting.xml in a custom place. If you create a new Maven project, you will find the Maven Settings in IDEA initialized again. This means that every time a new Maven project is imported, it needs to be reconfigured in IDEA, which is very uncomfortable.

Here’s another solution: After you change the Settings, all new projects will follow this setting.

This setting is located at: File ==> Other Settings ==> Default Settings