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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux下U盘文件系统类型的识别以及挂载

    手上有装好文件系统的CF一只,插上卡套,类比于U盘。1.先进入/mnt/目录新建一个usb目录cd/mnt/mkidrusb2.fdisk-l,然后插上U盘,fdisk-l查看是否有新的硬盘添加上来了?这时候我若是挂载是不知道sdb的文件类型的,也不清楚该挂载sdbx几。不需挂载就能查看的命令:

    2022年4月14日
    49
  • 微信小程序使用MQTT.js连接阿里云IoT物联网平台[通俗易懂]

    微信小程序使用MQTT.js连接阿里云IoT物联网平台[通俗易懂]前言最近公司要做物联网控制,觉得写app不能够兼容Android和iOS,于是选定了微信小程序来作为控制端,为了能够实时的监听到设备的状态变化,需要服务器能够主动推消息给小程序,一开始考虑了websocket,由服务器进行上报的数据监听,小程序使用websocket连接服务器接收消息,虽然能实现,但是加上业务逻辑之后就太复杂终归不好(因为服务器也是自己写–泪奔)于是想着,websocket既然…………………

    2022年8月31日
    13
  • 最小生成树的个数_最小生成树的实际应用

    最小生成树的个数_最小生成树的实际应用给定一张 N 个点 M 条边的无向图,求无向图的严格次小生成树。设最小生成树的边权之和为 sum,严格次小生成树就是指边权之和大于 sum 的生成树中最小的一个。输入格式第一行包含两个整数 N 和 M。接下来 M 行,每行包含三个整数 x,y,z,表示点 x 和点 y 之前存在一条边,边的权值为 z。输出格式包含一行,仅一个数,表示严格次小生成树的边权和。(数据保证必定存在严格次小生成树)数据范围N≤105,M≤3×105输入样例:5 61 2 11 3 22 4 33 5 4

    2022年8月10日
    8
  • JS合并数组对象中重复数据[通俗易懂]

    JS合并数组对象中重复数据[通俗易懂]数组重组数据源数据:目标数据://源数据varoldData=[{city_id:1,city_name:’北京’,city_img:”http://dfknbdjknvkjsfnvlkjdn.png”,city_country:”中国”},{city_id:2,city_name:’上海’,city_img:”http://wergerbe.png”,city_country

    2025年6月26日
    4
  • idea的maven插件在哪里_idea使用maven打包

    idea的maven插件在哪里_idea使用maven打包背景esayExcel版本升级

    2022年8月21日
    9
  • CentOS7在线安装gcc及使用

    CentOS7在线安装gcc及使用CentOS7在线安装gcc及使用一.在线安装gcc(需要配置网络)在虚拟机VMwareWorkstation安装CentOS7后,系统是没有gcc的。进入系统根目录[root@localhost~],输入命令:[root@localhost~]yum-yinstallgccgcc-c++autoconfmake就会自动进行在线安装。完成后输入命令:[root…

    2022年5月25日
    133

发表回复

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

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