用maven也大幾年了,也一直在用阿里雲的中央倉庫。
不喜歡在maven的settings.xml裏改,更喜歡直接在pom.xml裏改,由於受git管理,小夥伴們拉下來便可。html
然而網上的大部分技術文章都只會指導你這麼配置: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 )下載。spring
# 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。apache
查看maven的官方文檔(http://maven.apache.org/pom.h... ),能夠看到pom中除了repositories節點以外,還有一個關於倉庫的節點是pluginRepositories:api
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才能夠。
這也是網上大部分文章裏忽略掉的內容。。。。。maven
最終的pom文件以下:ide
<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,看看是否是都走了阿里雲的倉庫了。spring-boot