Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Idea compiling with SBT by default

Let's say I have a scala code, opening in 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). Click CTRL+SHIFT+F10 - to run.

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". I do it because I want to rely on SBT but not on IDE.

The question is: Is there a way to launch/compile in sbt by default in IntellyJ IDEA?

like image 263
ses Avatar asked Oct 26 '13 20:10

ses


People also ask

How compile sbt project in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.

Does sbt run compile?

sbt is a popular tool for compiling, running, and testing Scala projects of any size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies or more than one code file.

Is sbt a compiler?

Lightbend has made SBT's incremental compiler available as a standalone tool named Zinc, which can be used with other tools, like Maven.


1 Answers

Yup you can do it, but you'll need to make sure this is a valid SBT project. To verify, make sure you can compile and run from SBT on the command line.

  1. Install the SBT plugin for Intellij IDEA
  2. Open the run configuration for this Test in Run -> Edit Configurations...
  3. In the "Before Launch" section remove Make and add the SBT action "Run SBT Action 'compile'"

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.

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.

like image 103
swartzrock Avatar answered Sep 21 '22 17:09

swartzrock