【总结】Maven用阿里云作为中央仓库/国内镜像用法设置

素颜马尾好姑娘i 2022-04-15 06:27 669阅读 0赞

背景:

访问默认Maven中央仓库速度慢,故使用国内镜像,使用阿里云镜像仓库,加速开发效率。或者,搭建自己的Nexus私服,也可以实现同样的加速效果。

核心配置

编辑settings.xml文件

  1. <mirror>
  2. <!--This sends everything else to /public -->
  3. <id>nexus</id>
  4. <mirrorOf>*</mirrorOf>
  5. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  6. </mirror>
  7. <profiles>
  8. <profile>
  9. <id>nexus</id>
  10. <repositories>
  11. <repository>
  12. <id>central</id>
  13. <url>http://central</url>
  14. <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
  15. <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
  16. </repository>
  17. </repositories>
  18. <pluginRepositories>
  19. <pluginRepository>
  20. <id>central</id>
  21. <url>http://central</url>
  22. <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
  23. <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
  24. </pluginRepository>
  25. </pluginRepositories>
  26. </profile>
  27. </profiles>
  28. <activeProfiles>
  29. <activeProfile>nexus</activeProfile>
  30. </activeProfiles>

最终效果

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlbWluMTAwMw_size_16_color_FFFFFF_t_70

这样即可生效,亲测可用。

其他信息

自行也可以搭建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

20180411181545874

发表评论

表情:
评论列表 (有 0 条评论,669人围观)

还没有评论,来说两句吧...

相关阅读