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

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

   在这一篇博客:http://blog.youkuaiyun.com/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中添加:

  

-XX:MaxPermSize=512M
-Dplay.version=2.2.1
-Dsbt.ivy.home=/Users/macor/.ivy2
-Dsbt.repository.config=/Users/macor/.sbt/repo.properties<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">  </span>

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

[repositories]
local
Nexus osc : http://maven.oschina.net/content/groups/public/
Nexus osc thirdparty : http://maven.oschina.net/content/repositories/thirdparty/
typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
typesafe2: http://repo.typesafe.com/typesafe/releases/
sbt-plugin: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/
sonatype: http://oss.sonatype.org/content/repositories/snapshots
uk_maven: http://uk.maven.org/maven2/
ibibli: http://mirrors.ibiblio.org/maven2/
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文件,内容如下:

  

[repositories]
  local
  typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
  maven-central

[boot]
  directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}

[ivy]
  ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
  checksums: ${sbt.checksums-sha1,md5}
  override-build-repos: ${sbt.override.build.repos-false}
  repository-config: ${sbt.repository.config-${sbt.global.base-${user.home}/.sbt}/repositories}

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

[repositories]
local
oschina nexus:http://maven.oschina.net/content/groups/public/
typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
maven-central
sbt-plugins-repo: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
play: http://private-repo.typesafe.com/typesafe/maven-releases/
sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
typesafe-releases: https://repo.typesafe.com/typesafe/releases
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。




评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值