gpt4 book ai didi

sbt - 如何避免激活器在访问“播放”页面时两次执行编译任务?

转载 作者:行者123 更新时间:2023-12-04 04:30:21 25 4
gpt4 key购买 nike

我正在尝试在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次。有办法避免这种情况吗?

最佳答案

我遇到了同样的问题,并且找到了解决方案。

在Sbt中,您有三个Scopes by configuration axis:

  • Compile which defines the main build (src/main/scala).
  • Test which defines how to build tests (src/test/scala).
  • Runtime which defines the classpath for the run task.


您必须使用运行时而不是编译。它看起来应该像这样:
lazy val helloTask = taskKey[Unit]("hello")

helloTask := println("hello test")

(compile in Runtime) <<= (compile in Runtime) dependsOn helloTask

关于sbt - 如何避免激活器在访问“播放”页面时两次执行编译任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26533433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com