解决Maven下载依赖慢的问题

来源:互联网 发布:尔雅网络通识课 编辑:程序博客网 时间:2024/05/22 09:45

使用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>

0 0
原创粉丝点击