【问题标题】:How to configure Typesafe Activator not to use user home?如何配置 Typesafe Activator 不使用用户主页?
【发布时间】:2014-08-03 16:39:45
【问题描述】:

我想配置 Typesafe Activator,它是捆绑的工具,不使用我的用户主目录 - 我的意思是 ~/.activator(配置?),~/.sbt(sbt 配置?),尤其是 ~/.ivy2,我'我想在我的两个操作系统之间分享。 类型安全的“文档”帮助不大。

在 Windows 和 Linux 上都需要帮助。

【问题讨论】:

  • 到目前为止,我尝试挖掘启动脚本(Windows 上的 activator.bat),但它只引用了 %UserProfile%CFG_FILE_HOMECFG_FILE_VERSION,甚至改变它对 @987654327 的位置没有影响@ 目录已创建。

标签: sbt typesafe-activator


【解决方案1】:

来自sbt官方文档中的Command Line Options

  • 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,你必须将sbt/sbt.boot.properties 更改为activator-launch-1.2.2.jar。只需按照以下步骤操作:

  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

【讨论】:

  • 是的,它奏效了。我将-D... 选项放在~/.activator/activatorconfig.txt 中——无论如何,这个选项对于每个操作系统都应该不同,因为路径不同。感谢您的详尽解释。
  • 顺便说一句,我当时确实报告了这个问题,但忘记在此处附加。好像还开着github.com/typesafehub/activator/issues/585
【解决方案2】:

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

Windows:

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

Linux:

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

那么你应该很适合任何想要在你的主目录中存储数据的 Java 程序。

【讨论】:

  • 不应该是:export _JAVA_OPTIONS='-Duser.home=/local/home/me'
【解决方案3】:

作为对 Jacek 答案的补充,另一种设置 .ivy2 目录的方法是使用 sbt ivyConfiguration 任务。它返回与 ivy 相关的配置设置,包括 ivy 主页的路径(默认为~/.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 主目录的正确路径(此处为 ./.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

【讨论】:

    【解决方案4】:

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

    【讨论】:

    • 这没有回答问题,它是关于您是否可以将文件放在其他地方 - 而不是如何删除或恢复它们。
    猜你喜欢
    • 1970-01-01
    • 2015-10-10
    • 2013-10-25
    • 1970-01-01
    • 2015-02-12
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    相关资源
    最近更新 更多