Reputation: 507
I am new to Scala and to using emacs + ensime + sbt setup for my Scala development.
This setup is quite nice and light, but there is one thing which drives me nuts - inability to auto-compile / reload changes into Scala console started from sbt.
I use REPL a lot and would like to be able to start REPL from sbt with console
command and test my changes to scala classes from REPL without having to close it and reload every time I make a change.
I come from Erlang environment and this way of development is easy with Erlang but seems to be difficult with SBT. I have the JRebel plug-in installed but it doesn't seem to be working for the situation I described.
Has anybody been able to make something similar work and would be willing to share the configuration steps?
Much appreciated in advance.
Upvotes: 17
Views: 6011
Reputation: 6805
There are two things possible in sbt
:
Causing automatic recompilation of the project sources triggered by a file change by prefixing a command with ~
(tilde). The console
, or console-quick
, or console-project
commands can be prefixed, too, but you have to exit REPL to make the recompilation happen (just hit Ctrl+D
and wait.)
Causing automatic execution of REPL commands just after firing the console. They can be defined as properties (e.g. in build.sbt
):
console / initialCommands := """
import some.library._
def someFun = println("Hello")
"""
It's not necessary to define the property separately in consoleQuick
because it defaults to the one defined in console
, but if you would like to use the console-project
command you have to define it separately.
On a final note: remember to leave empty line between every property in an *.sbt
file. They're necessary to parse the properties correctly. In the example above there are no blank lines in between so it means that everything goes into the initialCommands
property (and that's what we want.)
Upvotes: 6