scala - 在 Play 中使用 System.getenv 在 build.sbt 中设置 ProjectRef?

标签 scala playframework sbt

我正在使用 OTHER_HOME环境变量指向不同的 SBT 项目目录。我打算将外部目录放在 maven 存储库中或通过 github.com#tag 项目引用,但现在我想向 Play 项目添加基于文件的依赖项。

我已经在 Build.scala 工作了风格:

val otherProjectDir = Option(System.getenv("OTHER_HOME"))
    .getOrElse("Set environment OTHER_HOME to your 'other' git clone")

// take the core sublibrary from other project
val otherCore = ProjectRef(file(otherProjectDir), "core")

val main = play.Project(appName, appVersion, appDependencies)
  .dependsOn(otherCore)

我想切换到 build.sbt ,但我不知道如何做到这一点。请指教。

最佳答案

看起来 play 有办法操纵他们的“监视服务”(监视文件的变化)。尝试将此添加到 build.sbt使重新加载等待一个小时(或您想要的时间):

PlayKeys.fileWatchService := play.runsupport.FileWatchService.sbt(3600000)

见这里:https://www.playframework.com/documentation/2.4.x/Migration24#playWatchService-renamed

如果您想完全禁用它,您应该能够创建自己的 FileWatchService 实例。并设置上面的键以使用您的自定义观察器(并使您的服务不执行任何操作)。就像是:
PlayKeys.fileWatchService := new FileWatchService {
  def watch(filesToWatch: Seq[File], onChange: () => Unit): FileWatcher = 
    new FileWatcher {
      def stop(): Unit = ()
    }
}

请注意,我还没有测试过这个片段,但你可以查看 FileWatchService 的来源。引用:https://github.com/playframework/playframework/blob/master/framework/src/run-support/src/main/scala/play/runsupport/FileWatchService.scala#L23

关于scala - 在 Play 中使用 System.getenv 在 build.sbt 中设置 ProjectRef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22176010/

相关文章:

java - Playframework 推送到 Websocket

java - 使用通配符 '*' 匹配 application.conf 中的任何内容 Play 应用程序

maven - sbt 0.11 : Using a corporate maven repository

scala - 如何使用 sbt 创建自定义 Scala 库?

scala - 在 sbt 中与 2.10.0 交叉构建

python - Scala 嵌套列表

scala - 找不到 sbt 启动器 0.11.2

scala - Apache Toree 和 Spark Scala 在 Jupyter 中不起作用

playframework - PersistenceException : Error with [models. Task]它尚未增强,但它是父类(super class)

scala - 在 IntelliJ IDEA 中找不到 SBT-shell