终极解决方案——sbt配置阿里镜像源,解决sbt下载慢,dump project structure from sbt耗时问题

#sbt下载慢的问题

默认情况下,sbt使用mvn2仓库下载依赖,如下载scalatest时,idea的sbtshell 显示如下url
此源速度很慢,用浏览器可以直接打开并测试速度,发现呵呵。
 
两种覆盖默认mvn2仓库解决方案,使用阿里云镜像
1.项目覆盖
resolvers += "central" at "http://maven.aliyun.com/nexus/content/groups/public/"
externalResolvers :=
Resolver.withDefaultResolvers(resolvers.value, mavenCentral = false)
2.全局覆盖
在~/.sbt/repositories添加如下内容(如果没有则创建这个文件)
[repositories]
local
my-maven-repo: http://maven.aliyun.com/nexus/content/groups/public

完成后,当在build.sbt添加依赖时,在idea的sbtShell可以看到如下内容
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/junit/junit/4.2/junit-4.2-sources.jar ...
[info] [SUCCESSFUL ] junit#junit;4.2!junit.jar(src) (1011ms)
[info] Writing structure to /tmp/sbt-structure.xml...
[info] Done.
这就表明更换镜像成功了,另外,sbt解析依赖过程也稍微耗时,不可能修改build.sbt后立即完成
dump project structure from sbt 过程

ps:官方文档
https://www.scala-sbt.org/0.13.2/docs/Detailed-Topics/Library-Management.html#override-all-resolvers-for-all-builds



更新
之前spark的jar包在阿里镜像上找不到,解析报错,于是又尝试了华为的镜像,可以正常使用,链接如下,在里面找到sbt即可
https://mirrors.huaweicloud.com/
推荐一个稳定速度还行的国外源
typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly

原文地址:https://www.cnblogs.com/lshao/p/10080223.html