Idea sets Maven like this, so you don't have to worry about the failure of dependent download any more
Little black brother downstairs 2021-06-04 10:35:03

Hello, Hello everyone , I'm little black brother downstairs .

B Website video version

So in today's video, we're going to bring a IDEA in Maven Tips for setting up .

So this technique can be said to be very useful , After learning how to set up , Don't worry about maven Depending on the problem of slow download .

Maven Set up

When we download and install Maven after , If not modified maven in setting Of documents .

By default , Maven The remote central warehouse address is a foreign address .

http://repo1.maven.org/maven2

Then our domestic network , because The power of mystery Influence , Visiting foreign addresses will be slower .

If your network is bad , Then it will be very slow to download the dependent resources with the default address , It's possible that the download will fail in the middle of the run .

In that case , We can set Maven Warehouse image address to solve this problem .

It can be used in China Maven In fact, there are many mirror addresses of , For example, Alibaba cloud

https://maven.aliyun.com/mvn/guide

NetEase :

https://mirrors.163.com/.help/maven.html

Tencent cloud :

https://mirrors.cloud.tencent.com/help/maven.html

So this one Maven Image address configuration is actually very simple .

Let's take Alibaba cloud as an example , Open the configuration tutorial of alicloud website .

We just need to copy this configuration to our installed Maven Of Setting Just in the file .

<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name> Alibaba cloud public warehouse </name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>

Then back IDEA in , open Maven Setup page , Set it up Setting.xml File address , And then click on this Override Button , Choose to override the default address .

Click save , Then download again , You'll find it's going to be a lot faster .

But there's a problem , This Maven The settings are only valid for the current project .

If you want to build a new one Maven Project , You'll find that IDEA in Maven The settings are initialized again .

in other words , Every time you build a new one Maven project , All need to be renewed in IDEA Set in Maven.

This is more boring !!!

Several times before IDEA Run in Maven project , Found that the package download dependency is particularly slow .

Last look , It turns out that Maven Setting reinitialization causes .

In this case, you should have met it ?

Well , Next, little black brother will teach you two solutions .

default setting

Then we use IDEA newly build Maven project ,IDEA in Maven The default settings are as follows :

IDEA In fact, it uses Maven Default contract address .

By default, it will be from the system user .m2 Read under the folder setting.xml This file .

So if you are mac user ,setting.xml The file address path is as follows :

/Users/${user}/.m2/setting.xml

So if you are windows user ,setting.xml The file address path is as follows :

C:\Users\${user}\.m2\setting.xml

This ${user} Refers to your current system login user name .

The first solution , It's very simple .

We put our own Setting Just move the file below the address mentioned above .

【 I can't beat you , Just add the expression pack 】

I can't beat you , Just join in .

After copying the past , The new project will load the default location setting.xml.

We have revised this document , The warehouse address is the image address we configured , Then the download will be fast .

I actually use this solution .

IDEA New project default settings

Then some of my friends may just want to setting.xml Put it in a place , Now let's teach you another solution .

We are IDEA Change some settings , In general, it will only take effect for the current project , Like this one Maven Set up .

that IDEA In fact, you can modify the default configuration of a new project .

After changing the settings , All new projects will follow this setting in the future .

So this setting is in :

File | New Projects Settings | Settings/Preferences for New Projects.

So if your IDEA The version is relatively low , Then the name of the setting place is different from that above .

File | Other Setting | Default Settings

 Picture from the Internet

Turn on this option , modify Maven Set up , Then click Finish .

In this way, all our new projects will use the configuration we just modified .

Re create another project , Open the... In the project , here Maven The default settings have been changed , Then we don't need to change the configuration manually .

Please bring the original link to reprint ,thank
Similar articles

2021-08-09

2021-08-09