sbt更改默认ivy仓库位置

转自: http://www.ituring.com.cn/article/132055


文档上有写:
http://www.scala-sbt.org/0.13/docs/Launcher-Configuration.html

一开始以为是要配置conf下的文件 sbt/0.13/conf/sbtopts

# Path to local Ivy repository (default: ~/.ivy2)
#
-ivy H:/repository/jar    

但配置后无效,sbt启动下载的jar依旧是放在了~/.ivy2
最后发现文档中的配置文件是在sbt\0.13\bin\sbt-launch.jar中的\sbt\sbt.boot.properties中(可用rar解压工具直接打开修改并覆盖),修改后内容如下:

    [scala]
      version: ${sbt.scala.version-auto}

    [app]
      org: ${sbt.organization-org.scala-sbt}
      name: sbt
      version: ${sbt.version-read(sbt.version)[0.13.7]}
      class: ${sbt.main.class-sbt.xMain}
      components: xsbti,extra
      cross-versioned: ${sbt.cross.versioned-false}
      resources: ${sbt.extraClasspath-}

    [repositories]
      local
      oschina nexus:http://maven.oschina.net/content/groups/public/
      typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[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

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

    [ivy]
      ivy-home: H:\repository\jar
      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}  

也可以通过修改sbt.bat(win下)的方式在启动命令后面加上参数指定。

不过对于第一个修改没有影响到仓库位置还是很诧异,注释上不是写了这个参数是仓库位置吗。或许是我理解错了。

 



把sbt-launch.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是远程仓库地址,boot就是设置.sbt目录,ivy设置.ivy2仓库目录,最后有个repository-config,我们可以在修改后的sbt目录下新建 repositories文件,填写访问速度快的仓库地址,会覆盖默认的repositories设置信息。另外sbt.boot.directory,sbt.ivy.home,sbt.repository.config 这些都是可配置的参数信息,相当于不用修改这配置文件,设置参数就行,但我在IDEA中设置的时候不起作用,使用-Dsbt.boot.directory=/xxx/xxx, 谁知道这种方式设置的请告知。最后修改后的如下:

[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: /Users/zhujiajun/Work/sbt/boot

[ivy]
  ivy-home: /Users/zhujiajun/Work/ivy-repository
  checksums: ${sbt.checksums-sha1,md5}
  override-build-repos: ${sbt.override.build.repos-false}
  repository-config: /Users/zhujiajun/Work/sbt/repositories

下面给出repositories文件内容,配置了OSC China的国内仓库,会优先去这里下载,没有的话去官方仓库下载,在下载jar的时候发现,大多数jar包会去官方 仓库下载,一些常用的可以在OSC上下载到,毕竟OSC是maven仓库地址。

[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文件更新到jar中,或者根据此配置文件重新打个jar包也可以。现在使用IDEA的时候,也会使用指定的目录了。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值