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?
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.
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.
Lightbend has made SBT's incremental compiler available as a standalone tool named Zinc, which can be used with other tools, like Maven.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With