【总结】Maven用阿里云作为中央仓库/国内镜像用法设置
背景:
访问默认Maven中央仓库速度慢,故使用国内镜像,使用阿里云镜像仓库,加速开发效率。或者,搭建自己的Nexus私服,也可以实现同样的加速效果。
核心配置
编辑settings.xml文件
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
最终效果
这样即可生效,亲测可用。
其他信息
自行也可以搭建Nexus私服,
可参考文档地址:https://www.cnblogs.com/rexfang/p/7625696.html
建议使用Nexus2旧版,不要使用Nexus3,旧版比新版功能好用一些
附加说明
Q: 为什么访问maven.aliyun.com/nexus/content/groups/public会返回404错误页面?
A:新版maven.aliyun.com还不支持通过这种方式浏览仓库,但是并不影响正常的构建下载。如果想浏览仓库内容请访问maven.aliyun.com/mvn/view页面,点击对应的仓库进行树状结构浏览。
Q:为什么首页显示的仓库地址变了,比如public仓的地址为https://maven.aliyun.com/repository/public?
A:首页上显示的仓库地址为推荐使用的仓库地址。为了保证兼容性也也支持以前的仓库地址,用户仍然可以通过http://maven.aliyun.com/nexus/content/groups/public来使用服务。
Q:首页无法浏览public库的内容?
A:public库是group库,其实代理了maven central和jcenter仓库。你可以浏览proxy库central或jcenter的内容,凡是里面有的包都可以通过public库下载。
Q:maven central中有的包在maven.aliyun.com中搜索不到?
A:目前只有缓存过的包才能在搜索界面搜索到。这个并不影响正常的构建使用。
Q:无法获取仓库的maven indexer文件?
A:目前还未支持生成和下载maven indexer文件。
Q:以前将maven.aliyun.com作为代理,代理到了自己的私服。现在貌似不工作了?
A:新版maven.aliyun.com还不支持作为远程库被代理.你可以直接使用maven.aliyun.com提供的仓库地址进行构建。如果仍想代理,也可以在私服机器上绑定旧的maven.aliyun.com的IP。将59.110.144.164 maven.aliyun.com
添加到私服机器的hosts文件中。注意:旧的站点以后可能会下线掉。
详见说明见:官方地址说明
-——————————————————————————-
-——————————————————————————-
关于我(个人域名)
我的开源项目集Github
期望和大家一起学习,共同进步,共勉,O(∩_∩)O谢谢
欢迎交流问题,可加个人QQ 469580884,
或者,加我的群号 751925591,一起探讨交流问题
不讲虚的,只做实干家
Talk is cheap,show me the code
还没有评论,来说两句吧...