Maven配置阿里云仓库下载依赖「建议收藏」

Maven配置阿里云仓库下载依赖「建议收藏」用过Maven的都知道Maven的方便便捷,但由于某些网络原因,访问国外的Maven仓库不便捷,maven默认使用的是国外的中央仓库,下载jar时有时候会因为网络不好等原因下载不全或失败,好在国内像阿里云、网易、JBoos、开源中国等大厂搭建了国内的maven仓库,阿里云的maven仓库使用的比较多:需要使用的话,要在maven的settings.xml文件里配置mirrors的子节点,添加…

大家好,又见面了,我是你们的朋友全栈君。

一、前言

用过Maven的都知道Maven的方便便捷,但由于某些网络原因,访问国外的Maven仓库不便捷,maven默认使用的是国外的中央仓库,下载jar时有时候会因为网络不好等原因下载不全或失败,好在国内像阿里云、网易、JBoos、开源中国等大厂搭建了国内的maven仓库,这里阿里云的maven仓库使用的比较多。

二、配置国内Maven仓库

需要使用的话,要在maven的settings.xml 文件里配置mirrors的子节点,添加如下mirror:


<!-- 指定本地Maven仓库存储地址 -->	
<localRepository>D:\path\developTool\apache-maven\Repository\springboot_repository</localRepository>

<mirrors>
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->	 
	<!-- 阿里云镜像仓库地址 -->		
	<mirror>    
     <id>alimaven</id>    
     <name>aliyun maven</name>    
     <url>http://maven.aliyun.com/nexus/content/groups/public/</url>    
     <mirrorOf>central</mirrorOf> 	
    </mirror>    
	
	<!--JBoos镜像地址镜像仓库地址 -->	
	<mirror>
     <id>jboss-public-repository-group</id>
     <name>JBoss Public Repository Group</name>
     <url>http://repository.jboss.org/nexus/content/groups/public</url>
     <mirrorOf>central</mirrorOf>
    </mirror> 
		
  	<!--oschina镜像地址镜像仓库地址 -->	
	<mirror>
     <id>CN</id>
     <name>OSChina Central</name>
     <url>http://maven.oschina.net/content/groups/public/</url>
     <mirrorOf>central</mirrorOf>
    </mirror>

</mirrors>

这样,在导入新项目,或者创建项目的时候, 边可使用配置的maven仓库下载依赖,提高速度;

三、Maven的完整setting.xml配置

通过自己平常在使用Maven时总结的一些经验,下面贴出一份比较全的Maven的setting.xml配置文件提供给大家参考:

<?xml version="1.0" encoding="UTF-8"?>

<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">
 
 
  <!-- 指定本地Maven仓库地址 -->
  <localRepository>D:\path\developTool\apache-maven\Repository\springboot_repository</localRepository>
 

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- 私服发布的用户名密码 -->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  
  <!-- 远程镜像仓库地址配置 -->
  <mirrors>
  
      <!-- 阿里云镜像仓库地址 -->   
    <mirror>  
     <id>nexus-aliyun</id>  
     <mirrorOf>central</mirrorOf>    
     <name>Nexus aliyun</name>  
     <url>http://maven.aliyun.com/nexus/content/groups/public</url>  
    </mirror> 
	  
	  <!--JBoos镜像地址镜像仓库地址 -->	
	<mirror>
     <id>jboss-public-repository-group</id>
     <name>JBoss Public Repository Group</name>
     <url>http://repository.jboss.org/nexus/content/groups/public</url>
     <mirrorOf>central</mirrorOf>
    </mirror> 
		
  	<!--oschina镜像地址镜像仓库地址 -->	
	<mirror>
     <id>CN</id>
     <name>OSChina Central</name>
     <url>http://maven.oschina.net/content/groups/public/</url>
     <mirrorOf>central</mirrorOf>
    </mirror>

  </mirrors>

  
  <!-- 配置: jdk1.8等, 先从阿里云下载, 没有再去私服下载  -->
  <profiles>
	
	    <!-- 全局JDK1.8配置、项目编码、项目编译jdk版本 -->
        <profile>
            <id>jdk1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>

		
		<!-- 企业内部Nexus私服仓库配置: 第三方jar包下载, 比如oracle的jdbc驱动等 -->
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>http://nexus.xxxxx.cn:8081/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>public</id>
                    <name>Public Repositories</name>
                    <url>http://nexus.xxxxx.cn:8081/nexus/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
		
		
		<!-- 阿里云配置: 提高国内的jar包下载速度 -->
	    <profile>    
		    <id>aliyun</id>
            <repositories>  
                <repository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>false</enabled>  
                    </snapshots>  
                </repository>  
            </repositories>  
            <pluginRepositories>  
                <pluginRepository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>  
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>false</enabled>  
                    </snapshots>  
                </pluginRepository>  
            </pluginRepositories>  
        </profile>  
	
  </profiles>

  <!-- 激活配置 --> 
  <activeProfiles> 
     <activeProfile>jdk1.8</activeProfile>  
     <activeProfile>dev</activeProfile>  
	 <activeProfile>aliyun</activeProfile> 
  </activeProfiles>
</settings>

四、Maven学习资料

Maven官方学习文档:http://maven.apache.org/guides/mini/guide-mirror-settings.html

 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/150541.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 远程调试部署在容器中的springboot项目「建议收藏」

    远程调试部署在容器中的springboot项目「建议收藏」问题:访问网站,会根据ip判断访客所处位置,但部分ip插入数据库失败。 以为是一次小问题,很快就解决了,没想到最终花了6个小时左右,才搞清楚。分析 :1、将本地程序跑起来,发现一切正常,可以插入到数据库。但问题在线上确实妥妥的出现的,而我现在日志级别是info,没有错误日志。所有准备Debug线上程序,之前只debug过使用基本的tomcat发布。而我现在的jar是使用docker构建的镜像,运行的镜像。 2、问题从线上转化到了,我需要远程debug线上程序发现问题,并将之解决。查各种资料,配置

    2022年6月13日
    25
  • e6600相当于amd_cpu核心电压

    e6600相当于amd_cpu核心电压据消费调研中心ZDC统计结果显示,2006年3月最受用户关注的前十款AMDCPU中,Athlon64和Sempron两大系列产品平分秋色,各有五款产品入围。具体产品排行如下图所示。(图)2006年3月最受用户关注的前十款AMDCPU排名产品名称报价L2缓存(KB)插槽类型主频(MHz)1¥990512Socket93918003¥765512Socket93918005¥1,120512S…

    2022年9月2日
    5
  • zoj 3509

    zoj 3509题目大意:N个点,M次加边/删边/询问两点连通性操作,初始图为空。N题解:想什么呢,大力bitset!N*N*M/32花式水过!附代码:#include#defineN510usingnamespacestd;bitsets[N],ned,now,emp;intn,m;inlineboolquery(inta,intb){ ned=now=s[a

    2022年7月12日
    13
  • 应用之星推出“图文app”制作工具,并附上教程「建议收藏」

    应用之星推出“图文app”制作工具,并附上教程

    2022年2月4日
    400
  • 2020年Android面试题汇总(初级)-简书_android经典面试题

    2020年Android面试题汇总(初级)-简书_android经典面试题Android面试题及答案(2022年最新Android面试题大全带答案),发现网上很多Android面试题整理都没有答案,所以花了很长时间搜集,本套Android面试题大全,Android面试题大汇总,有大量经典的Android面试题以及答案,包含Android语言常见面试题、Android工程师高级面试题及一些大厂Android开发面试宝典,面试经验技巧等,应届生,实习生,企业工作过的,都可参考学习!这套Android面试题汇总大全,希望对大家有帮助哈~此面试题合集分为9个部分:Java基础、And

    2022年8月28日
    0
  • LeetCode——Valid Palindrome

    LeetCode——Valid Palindrome

    2022年2月1日
    33

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号