关于intellij-idea:IDEA-Maven-源修改为国内阿里云镜像的正确方式

6次阅读

共计 1779 个字符,预计需要花费 5 分钟才能阅读完成。

前言

因为家喻户晓的起因,maven 的库在中国大陆十分慢。我在百度上搜到的大部分文章都是间接在~/.m2/settings.xml 退出以下内容。

  <mirrors>
    <mirror>
    <id>aliyunmaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>https://maven.aliyun.com/repository/public </url>
    </mirror>
  </mirrors>

其实这样设置,我发现其实镜像并没有扭转,还是 maven 的地方库。

正确的设置形式

在 maven 库的官网上 http://maven.apache.org/settings.html,是倡议咱们这样设置的。然而我发现,有时候,阿里云 maven 源有的包下载不了。所以我倡议设置如果阿里云下载不了,就去下载地方库。所以我的设置如下:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>central</mirrorOf>
     <name> 阿里云公共仓库 </name>
     <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    <mirror>
      <id>repo1</id>
      <mirrorOf>central</mirrorOf>
      <name>central repo</name>
      <url>http://repo1.maven.org/maven2/</url>
    </mirror>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>apache snapshots</mirrorOf>
     <name> 阿里云阿帕奇仓库 </name>
     <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>
  </mirrors>
  <proxies/>
  <activeProfiles/>
  <profiles>
    <profile>  
        <repositories>
           <repository>
                <id>aliyunmaven</id>
                <name>aliyunmaven</name>
                <url>https://maven.aliyun.com/repository/public</url>
                <layout>default</layout>
                <releases>
                        <enabled>true</enabled>
                </releases>
                <snapshots>
                        <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>MavenCentral</id>
                <url>http://repo1.maven.org/maven2/</url>
            </repository>
            <repository>
                <id>aliyunmavenApache</id>
                <url>https://maven.aliyun.com/repository/apache-snapshots</url>
            </repository>
        </repositories>             
     </profile>
  </profiles>
</settings>

IDEA 中的操作步骤

关上 IntelliJ IDEA->Settings ->Build, Execution, Deployment -> Build Tools > Maven

或者间接搜寻 maven

具体如下图所示:

正文完
 0