Idea使用系统自带的sbt,并自定义repositories

本文介绍了如何在IntelliJ IDEA中使用自定义的SBT repositories,以解决因默认源在国外导致的下载速度慢问题。通过修改Idea的SBT设置,创建repo.properties文件,并添加国内镜像,如Nexus osc、Sonatype等,从而提高下载速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在使用Idea + Scala + sbt (Macbook)做一些开发测试,但是由于默认使用国外的源,导致下载速度奇慢无比,所以想修改默认的repositories,但是怎么样才能修改默认的repositories并在Idea中使用修改后的配置呢?经过一天的折腾,总算是知道怎么新修改了,故在此备忘,也希望能帮助一些同学少走弯路。

   在这一篇博客:http://blog.csdn.net/suqier1314520/article/details/41775905中有提到修改Idea使用的sbt方法,即使用自定义路径的sbt, File -> Other settings ->Default settings -> Build,Execution,Deployment -> Build Tools -> SBT -> Launcher(sbt-launcher.jar) 改为Custom 找到sbt安装路径下的sbt-launcher.jar,并在VM Parameters中添加:

  

-Xmx2048M
-XX:MaxPermSize=512m
-XX:ReservedCodeCacheSize=256m
-Dsbt.log.format=true
-Dsbt.global.base=D:/JavaDev/.sbt
-Dsbt.boot.directory=D:/JavaDev/.sbt/boot/
-Dsbt.ivy.home=D:/JavaDev/.ivy2
-Dsbt.repository.config=D:/JavaDev/sbt/conf/repo.properties

  然后,手动创建文件D:/JavaDev/sbt/conf/repo.properties,并将如下内容加入到该文件:

[plain]  view plain  copy
  1. [repositories]  
  2. local  
  3. Nexus osc : http://maven.oschina.net/content/groups/public/  
  4. Nexus osc thirdparty : http://maven.oschina.net/content/repositories/thirdparty/  
  5. typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly  
  6. typesafe2: http://repo.typesafe.com/typesafe/releases/  
  7. sbt-plugin: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/  
  8. sonatype: http://oss.sonatype.org/content/repositories/snapshots  
  9. uk_maven: http://uk.maven.org/maven2/  
  10. ibibli: http://mirrors.ibiblio.org/maven2/  
  11. repo2: http://repo2.maven.org/maven2/  


  遗憾的是,Idea创建项目,并在build.sbt添加依赖后,默认还是从repo1.maven.org的库中下载,所以速度还是很慢。

  后来,我将Idea重的 Launcher(sbt-launcher.jar) 中的sbt可执行文件路径改为sbt安装目录下的sbt,并在/Users/macor/.sbt目录下,创建repositories(sbt默认会读取里面配置配好的repository地址),并将repo,properties的内容复制进去,删除repo.properties文件,再次在Idea中创建新的sbt项目,终于可以优先使用国内的repository了。


 

 此外,还在http://9leg.com/scala/2015/10/17/scala-play-setting.html发现另外一种方法(没尝试,估计也可行):把sbt-launcher.jar 解压出来,jar里面是编译好的class文件,其中在sbt目录下有一个sbt.boot.properties文件,内容如下:

  

[plain]  view plain  copy
  1. [repositories]  
  2.   local  
  3.   typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly  
  4.   maven-central  
  5.   
  6. [boot]  
  7.   directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}  
  8.   
  9. [ivy]  
  10.   ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}  
  11.   checksums: ${sbt.checksums-sha1,md5}  
  12.   override-build-repos: ${sbt.override.build.repos-false}  
  13.   repository-config: ${sbt.repository.config-${sbt.global.base-${user.home}/.sbt}/repositories}  

    在repositories配置项中添加自定义的国内镜像,可以是如下:

[plain]  view plain  copy
  1. [repositories]  
  2. local  
  3. oschina nexus:http://maven.oschina.net/content/groups/public/  
  4. typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly  
  5. maven-central  
  6. sbt-plugins-repo: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]  
  7. play: http://private-repo.typesafe.com/typesafe/maven-releases/  
  8. sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots  
  9. typesafe-releases: https://repo.typesafe.com/typesafe/releases  
  10. typesafe-ivy-releasez: https://repo.typesafe.com/typesafe/ivy-releases, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]  

   最后,把sbt.boot.properties打包进sbt-launcher.jar或者重新打包,即可修改默认的repository。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值