IntelliJ The idea of ​​compiling with SBT by default

Let's say I have a scala code that opens in an 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 I want to run this code, I click between the lines where object and def defined so that the IDE knows what I want to run (in this case, the whole object, because I do not select any method). Press CTRL + SHIFT + F10 - to start.

It starts up. I see a “Test” in my configuration layout ... But at that moment I stop the compilation process .. and move on to this configuration to change the configuration.

What I changed: this is the "Before you start" section to launch it using "sbt: compile" . I do this because I want to rely on SBT, but not on the IDE .

Question: Is there a way to run / compile in sbt by default in IntellyJ IDEA?

+6
source share
1 answer

You can do this, but you need to make sure that this is a valid SBT project. To check, make sure that you can compile and run from SBT on the command line.

  • Install SBT Plugin for Intellij IDEA
  • Open the launch configuration for this test in Run -> Edit Configurations ...
  • In the "Before starting" section, uncheck Make and add the SBT action "Run the SBT Action" compilation "

Now change your test code and run it again. You will see in the status bar that SBT compilation is performed before the test code is executed.

Update To make this default behavior for all future launch configurations, make this change in the "Default → Application" option in the "Edit Configurations ..." dialog box.

+3
source

Source: https://habr.com/ru/post/956800/


All Articles