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

来源:互联网 发布:中国网络空间安全战略 编辑:程序博客网 时间:2024/05/16 09:48

最近在使用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。
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 iphone触屏不灵怎么办 平板进水屏幕失灵怎么办 小米平板屏幕失灵怎么办 手机内屏变脏怎么办? 苹果手机屏幕触摸不灵敏怎么办 苹果6触控坏了怎么办 手机触摸屏不好使怎么办 手机触摸屏不好用怎么办 平板触屏不准怎么办 小米手机锁屏键失灵怎么办 三星手机锁屏键失灵怎么办 魅族2屏幕失灵怎么办 屏幕触屏不行怎么办 手机触屏失控怎么办 手机触屏不灵怎么办 电脑触屏不灵敏怎么办 iphone屏坏了怎么办 荣耀手机充电慢怎么办 苹果电池胶拉断怎么办 iphone8耳机丢了怎么办 华为p10进水了怎么办 苹果手机屏幕老是闪怎么办 苹果充电没反应怎么办 6sp开胶了怎么办 夜场ic微信怎么办 手机壳影响信号怎么办 三星开机键失灵怎么办 手机待机键失灵怎么办 手机关机键失灵怎么办 华为开关键失灵怎么办 iphone6plus屏幕碎了怎么办 苹果手机屏幕点不动怎么办 手机屏幕失灵划不动怎么办 苹果手机像素不好怎么办 苹果8指纹不灵敏怎么办 手机摔侧面裂缝怎么办 电脑触摸板进水怎么办 iphone部分屏幕失灵怎么办 苹果屏幕按键不灵怎么办 苹果4s老卡机怎么办 坚果2手机黑屏怎么办