用maven也大几年了,也一直在用阿里云的中央仓库。

不喜欢在maven的settings.xml里改,更喜欢直接在pom.xml里改,因为受git管理,小伙伴们拉下来即可。

然而网上的大部分技术文章都只会指导你这么配置:

<repositories>
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

如果你只是配置了repositories,那么你会发现在mvn在下载依赖的时候,一部分从阿里云下载,一部分还是从默认的仓库(https://repo.maven.apache.org )下载。

# mvn clean install
[INFO] Scanning for projects...
Downloading from aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-starter-parent/2.0.2.RELEASE/spring-boot-s
tarter-parent-2.0.2.RELEASE.pom
Downloaded from aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-starter-parent/2.0.2.RELEASE/spring-boot-st
arter-parent-2.0.2.RELEASE.pom (12 kB at 3.1 kB/s)
...
...
...
[INFO]
[INFO] --------------------------< com.zy:zy-parent >--------------------------
[INFO] Building zy-parent 1.0.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.pom (4.8 kB at 2.2 k
B/s)
...
...
...
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ zy-parent ---
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/3.0/maven-plugin-api-3.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/3.0/maven-plugin-api-3.0.pom (2.3 kB at 1.5 kB/s)
...
...
...
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ zy-parent ---
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/2.2.1/maven-plugin-api-2.2.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/2.2.1/maven-plugin-api-2.2.1.pom (1.5 kB at 1.2 kB/s)
...
...
...
[INFO] Installing E:\work\scratch\lily\src\zy-parent\pom.xml to D:\tools\maven\repo\com\zy\zy-parent\1.0.0-SNAPSHOT\zy-parent-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:25 min
[INFO] Finished at: 2019-11-14T10:13:53+08:00
[INFO] ------------------------------------------------------------------------

原来,只有项目本身的依赖,走了aliyun这个repository,maven命令需要的插件(比如clean、install都是maven的插件),走的还是默认的repository。

查看maven的官方文档(http://maven.apache.org/pom.html#Plugin_Repositories ),可以看到pom中除了repositories节点之外,还有一个关于仓库的节点是pluginRepositories:

Repositories are home to two major types of artifacts. The first are artifacts that are used as dependencies of other artifacts. These are the majority of plugins that reside within central. The other type of artifact is plugins. Maven plugins are themselves a special type of artifact. Because of this, plugin repositories may be separated from other repositories (although, I have yet to hear a convincing argument for doing so). In any case, the structure of the pluginRepositories element block is similar to the repositories element. The pluginRepository elements each specify a remote location of where Maven can find new plugins.

所以我们还需要再pom中增加pluginRepositories才可以。

这也是网上大部分文章里忽略掉的内容。。。。。

最终的pom文件如下:

<repositories>
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun-plugin</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

现在,你可以清空本地maven仓库中的包,然后再次执一下mvn clean install,看看是不是都走了阿里云的仓库了。

pom中更换阿里云仓库时不要忽略了pluginRepositories的更多相关文章

  1. maven更换阿里云仓库

    本来不想写,网上到处都是,不过好多到我这不行,自己记录下,省的到处找 D:\apache-maven-3.6.1\conf目录下setting.xml文件(这是我的解压的位置) <mirrors ...

  2. 在Maven项目中,指定使用阿里云仓库下载jar包

    Maven项目中,在pom.xml的</project>标签之前加入一下标签,指定使用阿里云仓库下载jar包. <!-- 使用aliyun maven --> <repo ...

  3. 将Maven镜像更换为国内阿里云仓库

    1.国内访问maven默认远程中央镜像特别慢 2.用阿里的镜像替代远程中央镜像 3.大部分jar包都可以在阿里镜像中找到,部分jar包在阿里镜像中没有,需要单独配置镜像 换为国内镜像,让你感受飞一般的 ...

  4. clojure 使用阿里云仓库

    clojure 使用阿里云仓库 学习一门语言,如果没有梯子真的是一件非常痛苦的事情,好在阿里巴巴为我们java程序员提供了maven镜像.近期学习clojure,为了找解决方案在stackoverfl ...

  5. 在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现Web端直传,服务端签名直传并设置上传回调的实现流程

    在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现本地文件上传流程 by shuijingwan · 2016/01/13 1.SDK安装 github ...

  6. 【阿里云产品公测】在Laravel4框架中使用阿里云ACE的缓存服务

    作者:阿里云用户dvbhack 受论坛排版和格式限制,这篇帖子的格式不是很利于阅读,如果你看帖子觉得不那么舒服,可以看我发表在自己博客上的原文:http://www.ofcss.com/2014/04 ...

  7. [Java] Spring boot 的maven设置阿里云仓库

    Spring boot 的maven设置阿里云仓库 打开根目录下的 pom.xml 文件,在对应为止出加入如下 红色 代码: <build> <plugins> <plu ...

  8. 安装Ubuntu服务器版 + 远程连接ssh +更换阿里云源

    安装Ubuntu服务器版 1.点击 "开启此虚拟机",开始安装. 2.默认选择English,英文版安装,直接按Enter键即可. 3.默认选择"Install Ubun ...

  9. Ubuntu系统中登陆阿里云服务器的方法

    如果您购买了阿里云服务器,恰巧又在使用Ubuntu操作系统,那么恭喜你来对地方了,今天给大家分享一下如何在Ubuntu中登陆阿里云服务器: 主要使用两款软件:1.SecureCRT:2.SecureF ...

随机推荐

  1. Python破解js加密实例(有道在线翻译)

    在爬虫爬取网站的时候,经常遇到一些反爬虫技术,比如: 加cookie,身份验证UserAgent 图形验证,还有很难破解的滑动验证 js签名验证,对传输数据进行加密处理 对于js加密经过加密传输的就是 ...

  2. Maven环境搭配及继承

    1. Maven简单介绍 Apache Maven是个项目管理和自动构建工具,基于项目对象模型(POM)的概念. 作用:完成项目的相关操作,如:编译,构建,单元测试,安装,网站生成和基于Maven部署 ...

  3. javaweb里html的一些基本代码意义(学)

    <html> <head> <title>body.text属性示例</title> </head> <body text=" ...

  4. Java开发在线考试系统 使用ssh框架编写源码

    开发工具: Eclipse,  Tomcat,  MySql       1.  登录页面登录功能, 输入用户名与密码, 选择角色, 滑动箭头拉到最右边才可以点击登录       2.  学生角色登录 ...

  5. 高精度gcd

    #include<iostream> #include<cstdio> #include<cstring> #define inf 1000000000 using ...

  6. Jenkins + Pipeline + Git + Maven (十)

    一.准备环境介绍 192.168.5.71 # gitlab 仓库IP 192.168.5.72 # 开发环境,用于提交代码等 192.168.5.73 # tomcat 部署solo服务站点 192 ...

  7. Spark之RDD

    Spark学习之路Spark之RDD 目录 一.RDD的概述 1.1 什么是RDD? RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是Spark中最基本的数 ...

  8. MongoDB 之pymongodb

    import pymongo import json from bson import ObjectId mongoclient = pymongo.MongoClient(host="12 ...

  9. 不知道多大的文件不要用cat查看!

    今天长清女子学校的主任给我微信上发了一图片,说登录服务器的时候就查看了一个文件,结果服务器的风扇忽然变的特别响,系统慢了好多,让我看看是什么回事!我当时心里想,无缘无故怎么会这样,难不成是进病毒了?查 ...

  10. nginx发布静态资源

    nginx发布静态资源 参考 ngx_http_index_module index指令 ngx_http_core_module http指令 location指令 listen指令 root指令 ...