【发布时间】:2014-12-19 10:28:36
【问题描述】:
我正在尝试在编译 Play 2.3 应用程序之前运行自定义任务。我的build.sbt 文件中有这个:
lazy val helloTask = TaskKey[Unit]("hello", "hello")
helloTask := {
println("hello test")
}
(compile in Compile) <<= (compile in Compile) dependsOn helloTask
当我运行activator ~run 然后在浏览器中打开一个页面时,我得到以下输出:
C:\Development\test>activator ~run
[info] Loading project definition from C:\Development\test\project
[info] Set current project to play (in build file:/C:/Development/test/)
--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
hello test
[success] Compiled in 418ms
hello test
hello test
[info] play - Application started (Dev)
我的自定义任务似乎运行了 3 次。有没有办法避免这种情况?
【问题讨论】:
-
有趣。加载页面似乎会触发
compile两次。 I'd report an issue. -
顺便说一句,使用较短的版本
taskKey定义一个新任务 -lazy val hello = taskKey[Unit]("My custom hello task")。 -
最终....新版本可能会解决此问题
-
同样的问题是否会导致资产任务也被编译两次?
-
有什么更新吗?我们可以观察到同样的问题(play 2.3.8, sbt 13.7, scala 2.11.5)。在我们的例子中,任务被一遍又一遍地执行。
标签: sbt playframework-2.3 typesafe-activator