how to auto-reload changed scala classes into SBT REPL
Asked Answered
P

1

16

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.

Paschasia answered 10/11, 2013 at 19:27 Comment(0)
S
5

There are two things possible in sbt:

  1. 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.)

  2. Causing automatic execution of REPL commands just after firing the console. They can be defined as properties (e.g. in build.sbt):

    initialCommands in console := """
    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.)

Shakeup answered 11/11, 2013 at 0:54 Comment(3)
thanks Rajish for replying - this is not exactly what I was looking for. If one needs to exit / open REPL after every change to get changes reloaded it just means that interactive Scala development (at least in the same sense as LISP or Erlang developers understand it) is not possible.Paschasia
I'm afraid nothing else is possible, currently. There is the issue in the ensime github repo github.com/aemoncannon/ensime/issues/149, but nothing has happened since three years, so 'pull requests are welcome' ;)Shakeup
If you need nice real-time updated REPL experience maybe you should try the Scala-IDE worksheets github.com/scala-ide/scala-worksheet/wiki/Getting-StartedShakeup

© 2022 - 2024 — McMap. All rights reserved.