1. 程式人生 > >終極解決方案——sbt配置阿里映象源,解決sbt下載慢,dump project structure from sbt耗時問題

終極解決方案——sbt配置阿里映象源,解決sbt下載慢,dump project structure from sbt耗時問題

#sbt下載慢的問題

預設情況下,sbt使用mvn2倉庫下載依賴,如下載scalatest時,idea的sbtshell 顯示如下url https://repo1.maven.org/maven2/org/scalatest/scalatest_2.10/3.0.1/scalatest_2.10-3.0.1.jar  此源速度很慢,用瀏覽器可以直接開啟並測試速度,發現呵呵。   兩種覆蓋預設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