在Play中,使用System.getenv来设置build.sbt中的ProjectRef?

5

我使用 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,但是我不知道如何做。请给予建议。


明确一点,它可以工作,但我在子项目方面遇到了问题。 - Jaap
只需将其复制并粘贴到 build.sbt 中,无需更改。你试过了吗? - Jacek Laskowski
你遇到了什么问题?不知道症状是什么,很难确定如何修复。 - jsuereth
不清楚 build.sbt 是如何工作的,它是一个 Scala 文件吗?它不包含导入,而且对于行结束非常挑剔,因此将 Build.scala 代码复制粘贴到 build.sbt 中似乎是错误的。 - Jaap
1个回答

0

看起来 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接