解决Maven下载依赖慢的问题

使用Maven构建项目时,项目中有的依赖包可能下载的非常慢,我们可以通过配置镜像来解决这个问题。 
之前开源中国的那个好像已经关闭了,于是我找到了一个阿里的来解决。 
在Maven的配置文件(%MAVEN%/conf/setting.xml)中的< mirrors> 标签中加入

      <!-- 阿里云仓库 -->
      <mirror>
           <id>alimaven</id>
           <mirrorOf>central</mirrorOf>
           <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
         </mirror>

       <!-- 中央仓库1 -->
        <mirror>
            <id>repo1</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
         </mirror>
        <!-- 中央仓库2 -->
        <mirror>
           <id>repo2</id>
           <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
           <url>http://repo2.maven.org/maven2/</url>
        </mirror>
这样我们在引入依赖的时候,速度就可以嗖嗖的了。 
注意:有的版本比较高的依赖包,这个阿里的仓库也可能没有。所以要么用老的依赖,要么删掉镜像配置,继续去中央仓库下载最新的依赖。

附上setting.xml文件

<settings>
  <mirrors>
     <!-- 阿里云仓库 -->
      <mirror>
           <id>alimaven</id>
           <mirrorOf>central</mirrorOf>
           <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
         </mirror>

       <!-- 中央仓库1 -->
        <mirror>
            <id>repo1</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
         </mirror>
        <!-- 中央仓库2 -->
        <mirror>
           <id>repo2</id>
           <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
           <url>http://repo2.maven.org/maven2/</url>
        </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
		<repository>
            <id>spring-release</id>
            <name>Spring Maven Release Repository</name>
            <url>http://repo.springsource.org/libs-release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

  <!-- deploy artifacts to repository. -->
  <servers>
    <server>
	  <id>releases</id>
	  <username>username</username>
	  <password>PASSWORD</password>
	</server>
	<server>
	  <id>snapshots</id>
	  <username>username</username>
	  <password>PASSWORD</password>
	</server>
  </servers>

</settings>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值