[英]IntelliJ Idea compiling with SBT by default
Let's say I have a scala
code, opening in intellij idea
:假设我有一个
scala
代码,在intellij idea
打开:
object Test extends App {
// <- I click here
def init[T](xs: List[T]) : List[T] = xs match {
case List() => throw new Error("empty list")
case List(x) => List() // empty list
case head :: tail => head :: init(tail)
}
val list = List(1,2,4)
println ( init(list) )
}
Then, what I do when want to launch this code, I click between lines where object
and def
is defined to let IDE
know what I want to launch (in this case whole object, because I do not select any method).然后,当我想要启动这段代码时,我会在定义
object
和def
行之间单击,让IDE
知道我想要启动的内容(在这种情况下是整个对象,因为我没有选择任何方法)。 Click CTRL+SHIFT+F10 - to run.单击CTRL+SHIFT+F10 - 运行。
It starts.. I see "Test" in my configuration combo-box... But at that exact moment I stop compilation process .. and go to that configuration to change the config ..它开始......我在我的配置组合框中看到“测试”......但在那一刻我停止编译过程......并转到该配置以更改配置......
What I change: is "Before launch" section to make it run with "sbt:compile" .我改变的是: “启动前”部分,使其与“sbt:compile”一起运行。 I do it because I want to rely on SBT but not on IDE .
我这样做是因为我想依赖 SBT 而不是 IDE 。
The question is: Is there a way to launch/compile in sbt by default in IntellyJ IDEA?问题是:有没有办法在 IntellyJ IDEA 中默认在 sbt 中启动/编译?
Yup you can do it, but you'll need to make sure this is a valid SBT project.是的,您可以这样做,但您需要确保这是一个有效的 SBT 项目。 To verify, make sure you can compile and run from SBT on the command line.
要进行验证,请确保您可以在命令行上从 SBT 编译和运行。
Now modify your Test code and re-run.现在修改您的测试代码并重新运行。 You'll see in the status bar that SBT compile is being run before your Test code executes.
在执行测试代码之前,您将在状态栏中看到 SBT 编译正在运行。
Updated To make this the default behavior for all future run configurations, make this change in the Defaults -> Application item in the Edit Configurations... dialog.更新为了使其成为所有未来运行配置的默认行为,请在“编辑配置...”对话框的“默认”->“应用程序”项中进行此更改。
Let me update this as this still comes up when searching for a solution.让我更新一下,因为在搜索解决方案时仍然会出现这种情况。 The SBT plugin is now depreciated and we can configure building by SBT from the IntelliJ preferences:
SBT 插件现已弃用,我们可以从 IntelliJ 首选项中配置 SBT 构建:
Preferences --> Build, Execution, Deployment --> Build Tools --> sbt: Use SBT shell for imports, for builds首选项 --> 构建、执行、部署 --> 构建工具 --> sbt:使用 SBT shell 进行导入和构建
See https://blog.jetbrains.com/scala/2017/03/23/scala-plugin-for-intellij-idea-2017-1-cleaner-ui-sbt-shell-repl-worksheet-akka-support-and-more/ for more details.见https://blog.jetbrains.com/scala/2017/03/23/scala-plugin-for-intellij-idea-2017-1-cleaner-ui-sbt-shell-repl-worksheet-akka-support-and -more/了解更多详情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.