Saturday, October 9, 2010

Turn FSC (Fast Scala Compiling) on in IDEA

I've tried turning the 'fsc' (Fast Scala Compilation) option on in IntelliJ IDEA before and it has always failed miserably (usually with a java.lang.reflect.InvocationTargetException from the scala.tools.nsc.CompileClient via sun.reflect.NativeMethodAccessorImp.invoke0) and I've never been able to find the solution before.

Well, my google-fu must have been turned up to 11 today because I found this post detailing how to start the compilation server from within IDEA.

To save you reading the whole thread, the solution is just:
1. Open the 'Edit (Run/Debug) Configurations' dialog
2. Click on the [+]
3. Select 'Scala Compilation Server' (should be near the end of the list)
4. Give the new launcher a name (e.g. 'fsc')
5. Hit OK
6. Press the Play icon

Assuming you're also sensible enough to turn on the 'Use fsc (fast scalac)' option (it's under 'Scala Compiler' in the Project Settings), re-compilation of .scala files should get a LOT faster with fsc. I'm seeing single-file changes have gone down from over 10 seconds to less than one.

3 comments:

  1. I have been struggling with FSC in IDEA myself for ages. Thank you for this concise solution. I hope the JetBrains folks make FSC somehow work by default at some point in the future. It makes a huge difference.

    ReplyDelete
  2. I think your experience with fsc must be different than mine. I've found it to be buggy in that (1) it just won't work on some computers, and (2) it sometimes won't recompile when a recompile is necessary.
    Yes it is faster, but every time I've used it I ended up giving up in favor of scalac.

    ReplyDelete
  3. Hi Yuvi. Thanks for your comment. I only turned it on a couple of days ago and haven't done a whole lot of coding since then, so I'll have to wait and see whether I have problems, too. Perhaps I'll need to do a future post about how to turn FSC off. ;)
    Cheers,
    Graham.

    ReplyDelete