Thursday, 15 July 2010

Tech Tip: How to use fast scala compiler (fsc) from IntelliJ IDEA

Using fsc from IDEA is supposed to be trivial task. IDEA provides dedicated fsc "Run Configuration" out-of-the-box. Unfortunately in reality things are getting more complicated. Scala build in IDEA is hanging more or less often making it not usable.

It took me several hours to figure out what is going on there. I was trying with dozen of switches without success. Finally I've found this simple answer and here it is.

When compiler server is starting it opens random port to listen for commands from compiler clients. Obviously the clients must know that port number. To communicate that server is creating file named as the port number. The file is created under JVM temporary directory ${java.io.tmpdir}/scala-devel/ ... (/tmp/scala-devel/{username}/scalac-compile-server-port/ at my linux box). Problems begin if there are some old unused files left in that directory. So the solution is easy - delete ${java.io.tmpdir}/scala-devel/ before starting compiler server.

I've created simple bash script to do that. I simply use it instead of starting fsc from IDEA.

5 komentarze:

Eugen said...

Thank You, Krzysztof!
Your recipe does really help.

I've added "fsc -shutdown" at the beginning of the bash script, too.


Best regards,
Eugen Labun

Anonymous said...

Thanks, Krysztof

Leszek Gruchała said...

Do you do anything with idea options like:
- reset fsc server
- shutdown fsc server
?
How IDEA knows to which port to connect?

Thanks

Krzysztof Białek said...

Regarding the IDEA options: As far as I can remember I was trying all possible combinations without success.

Regarding fsc port: When configured to use fsc, IDEA starts fsc client complier as separate java process and from my understanding the client is responsible for picking the right port by looking at "port" file in directory /tmp/scala-devel//scalac-compile-server-port/

I hope that helps you.

Jeremy Collins said...

Thank you. This worked perfectly, and enabling fsc really helped with the make time.