如何将Typesafe Activator配置为不使用用户主页



我想配置Typesafe Activator,它是不使用我的用户主目录的捆绑工具-我指的是~/.activator(配置?(、~/.sbt(sbt配置?(,尤其是~/.ivy2,我想在我的两个操作系统之间共享它。Typesafe的"文档"帮助不大。

需要Windows和Linux的帮助。

sbt:官方文档中的命令行选项

  • sbt.global.base-包含全局设置和插件的目录(默认值:~/.sbt/0.13(
  • sbt.ivy.home-包含本地Ivy存储库和工件缓存的目录(默认值:~/.ivy2(

~/.activator似乎已设置并在启动脚本中使用,这就是我更改值的地方。

还显示(在activator-launch-1.2.1.jar中的sbt/sbt.boot.properties中(ivy-home的值为${user.home}/.ivy2:

[ivy]
  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}

这意味着,如果不进行一些开发,就只能更改sbt.global.base

➜  minimal-scala  activator -Dsbt.global.base=./sbt -Dsbt.ivy.home=./ivy2 about
[info] Loading project definition from /Users/jacek/sandbox/sbt-launcher/minimal-scala/project
[info] Set current project to minimal-scala (in build file:/Users/jacek/sandbox/sbt-launcher/minimal-scala/)
[info] This is sbt 0.13.5
[info] The current project is {file:/Users/jacek/sandbox/sbt-launcher/minimal-scala/}minimal-scala 1.0
[info] The current project is built against Scala 2.11.1
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4

如果您想查看后台,可以使用consoleProject命令查询sbt和Ivy主目录的当前值(假设您使用activator -Dsbt.global.base=./sbt -Dsbt.ivy.home=./ivy2启动activator(:

> consoleProject
[info] Starting scala interpreter...
[info]
import sbt._
import Keys._
import _root_.sbt.plugins.IvyPlugin
import _root_.sbt.plugins.JvmPlugin
import _root_.sbt.plugins.CorePlugin
import _root_.sbt.plugins.JUnitXmlReportPlugin
import currentState._
import extracted._
import cpHelpers._
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
scala> appConfiguration.eval.provider.scalaProvider.launcher.bootDirectory
res0: java.io.File = /Users/jacek/sandbox/sbt-launcher/minimal-scala/sbt/boot
scala> appConfiguration.eval.provider.scalaProvider.launcher.ivyHome
res1: java.io.File = /Users/jacek/.ivy2

如果你真的想说服Activator使用sbt.ivy.home,你必须在activator-launch-1.2.2.jar中更改sbt/sbt.boot.properties。只需遵循以下步骤:

  1. activator-launch-1.2.2.jar中取出sbt/sbt.boot.properties

    jar -xvf activator-launch-1.2.2.jar sbt/sbt.boot.properties
    
  2. 编辑sbt/sbt.boot.properties,将ivy-home替换为[ivy]

    ivy-home: ${sbt.ivy.home-${user.home}/.ivy2}
    
  3. 将更改后的sbt/sbt.boot.properties添加到activator-launch-1.2.2.jar

    jar -uvf activator-launch-1.2.2.jar sbt/sbt.boot.properties
    

经过更改,-Dsbt.ivy.home=./ivy2运行良好。

scala> appConfiguration.eval.provider.scalaProvider.launcher.bootDirectory
res0: java.io.File = /Users/jacek/sandbox/sbt-launcher/minimal-scala/sbt/boot
scala> appConfiguration.eval.provider.scalaProvider.launcher.ivyHome
res1: java.io.File = /Users/jacek/sandbox/sbt-launcher/minimal-scala/ivy2

我今天正在试验这个。过了一段时间,在我看来这可能是最好的做法:

窗口:

setx _JAVA_OPTIONS "-Duser.home=C:/my/preferred/home/"

Linux:

export _JAVA_OPTIONS='-Duser.home=/local/home/me'

然后,您应该可以选择任何希望将数据存储在主目录中的Java程序。

除了Jacek的回答之外,我设置.ivy2目录的另一种方法是使用sbt ivyConfiguration任务。它返回与ivy相关的配置设置,包括ivy home的路径(默认为~/.ivy2的路径(。

只需将这几行添加到项目中的build.sbt文件中即可:

ivyConfiguration ~= { originalIvyConfiguration =>
  val config = originalIvyConfiguration.asInstanceOf[InlineIvyConfiguration]
  val ivyHome = file("./.ivy2")
  val ivyPaths = new IvyPaths(config.paths.baseDirectory, Some(ivyHome))
  new InlineIvyConfiguration(ivyPaths, config.resolvers, config.otherResolvers,
    config.moduleConfigurations, config.localOnly, config.lock,
    config.checksums, config.resolutionCacheDir, config.log)
}

它返回一个与原始ivy配置相同的新ivy配置,但ivy主目录的路径正确(此处为./.ivy2,因此它将位于build.sbt文件旁边(。这样,当sbt使用ivyConfiguration任务来获取ivy配置时,.ivy2目录的路径将是上面设置的路径。

使用sbt 0.13.50.13.8对我有效。

注意:对于sbt版本0.13.6及以上版本,InlineIvyConfiguration的构造需要一个额外的参数,以避免被标记为不推荐使用,因此您可能需要将最后一行更改为:

new InlineIvyConfiguration(ivyPaths, config.resolvers, config.otherResolvers,
  config.moduleConfigurations, config.localOnly, config.lock,
  config.checksums, config.resolutionCacheDir, config.updateOptions, config.log)

(注意附加的config.updateOptions(

我在Mac上遇到了同样的问题。我删除了用户主目录中名为.activator的目录和所有相关文件夹。之后在终端上运行activator run命令。激活器下载我删除的所有文件夹。比解决问题更重要。

最新更新