1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Maven阿里云与本地仓库配置

Maven阿里云与本地仓库配置

时间:2022-04-28 16:40:28

相关推荐

Maven阿里云与本地仓库配置

本文来说下Maven阿里云与本地仓库配置

文章目录

阿里云中央仓库配置的原因阿里云中央仓库配置的两种方法pluginRepositories标签本文小结

阿里云中央仓库配置的原因

在pom.xml文件里配置了一些依赖,如下图

但因为默认的Maven仓库是在国外,引入这些依赖的时候,可能速度非常慢,于是阿里云做了一个中央仓库,把Maven仓库里的所有jar包复制过来,从阿里云仓库中引入依赖就变得很轻松了。

阿里云中央仓库配置的两种方法

修改maven根目录下的conf文件夹中的setting.xml文件,内容如下:

<mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf></mirror> </mirrors>

在pom.xml中直接添加

<!-- 代码库 --><repositories><repository><id>maven-ali</id><url>/nexus/content/groups/public//</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy><checksumPolicy>fail</checksumPolicy></snapshots></repository></repositories>

pluginRepositories标签

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

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

查看maven的官方文档(/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>public</id><name>aliyun nexus</name><url>/nexus/content/groups/public/</url><releases><enabled>true</enabled></releases></repository></repositories><pluginRepositories><pluginRepository><id>public</id><name>aliyun nexus</name><url>/nexus/content/groups/public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></pluginRepository></pluginRepositories>

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

本文小结

本文介绍了Maven阿里云与本地仓库的基本配置信息。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。