Reputation: 13342
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?
Upvotes: 9
Views: 5257
Reputation: 850
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:
Preferences --> Build, Execution, Deployment --> Build Tools --> sbt: Use SBT shell for imports, for builds
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.
Upvotes: 1
Reputation: 729
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.
Upvotes: 3