SBT停止运行而不退出
如何在不退出的情况下终止 SBT 中的运行?
我正在尝试 CTRL+C 但它退出 SBT。有没有办法在保持 SBT 打开的情况下仅退出正在运行的应用程序?
How do you terminate a run in SBT without exiting?
I'm trying CTRL+C but it exits SBT. Is there a way to only exit the running application while keeping SBT open?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从 sbt 版本 0.13.5 开始,您可以将其添加到您的 build.sbt 中,
它被定义为“启用(true)或禁用(false)使用 CTRL+C 中断任务执行的能力”。 在 键定义中。
如果您使用的是 Scala 2.12,则 7+ 您还可以使用 CTRL+C 取消编译。参考https://github.com/scala/scala/pull/6479
有一些报告的错误:
From sbt version 0.13.5 you can add to your build.sbt
It is defined as "Enables (true) or disables (false) the ability to interrupt task execution with CTRL+C." in the Keys definition
If you are using Scala 2.12.7+ you can also cancel the compilation with CTRL+C. Reference https://github.com/scala/scala/pull/6479
There are some bugs reported:
在默认配置中,您的运行发生在 sbt 运行的同一个 JVM 中,因此您无法轻松地单独杀死它们。
如果您在单独的分叉 JVM 中运行,如 Forking 中所述,那么你可以终止该 JVM(通过操作系统提供的任何方式),而不影响 sbt 的 JVM:
In the default configuration, your runs happen in the same JVM that sbt is running, so you can't easily kill them separately.
If you do your run in a separate, forked JVM, as described at Forking, then you can kill that JVM (by any means your operating system offers) without affecting sbt's JVM:
当我可以控制从 sbt 运行的应用程序的主循环时,我发现以下内容很有用。
我告诉 sbt 在运行应用程序时进行 fork(在 build.sbt 中):
我还告诉 sbt 将 stdin 从 sbt shell 转发到应用程序(在 build.sbt 中):
最后,在应用程序的主线程中,我等待stdin 上的文件结尾,然后关闭 JVM:
当然,您可以使用任何线程读取 stdin 并关闭,而不仅仅是主线程。
最后启动sbt,可选择切换到你要运行的子项目,运行。
现在,当您想要停止该进程时,请通过在 sbt shell 中键入 CTRL-D 来关闭其标准输入。
I've found the following useful when I have control over the main loop of the application being run from sbt.
I tell sbt to fork when running the application (in build.sbt):
I also tell sbt to forward stdin from the sbt shell to the application (in build.sbt):
Finally, in the main thread of the application, I wait for end-of-file on stdin and then shutdown the JVM:
Of course, you can use any thread to read stdin and shutdown, not just the main thread.
Finally, start sbt, optionally switch to the subproject you want to run, run.
Now, when you want to stop the process, close its stdin by typing CTRL-D in the sbt shell.
考虑使用 sbt-revolver。我们公司就用它,非常方便。
对于您所要求的,可以通过以下方式完成:
无需配置 build.sbt 文件。
您可以通过添加以下内容来使用此插件:
到您的project/plugins.sbt
Consider using sbt-revolver. We use it in our company and it's really handy.
For what you're asking can be done with:
Without need to configure build.sbt file.
Your can use this plugin by adding:
To your project/plugins.sbt