Saturday, January 16, 2010

IntelliJ Scala Plugin Compile Errors

Are you trying your first steps with Scala like I do, using IntelliJ with its Scala plug-in?
Do you see something like the following while trying to compile you Scala source code?

Information:Compilation completed with 3 errors and 0 warnings
Information:3 errors
Information:0 warnings
Error: error while loading Predef, Scala signature Predef has wrong version
Error:expected: 5.0
Error:found: 4.1 in C:\Users\\.m2\repository\org\scala-lang\scala-library\2.7.7\scala-library-2.7.7.jar(scala/Predef.class)

Well, if you are clueless like I was it might interest you that this problem is most likely coming from a lack of backwards compatibility in compiler version and that the IntelliJ plug-in for Scala that I use seems to use a newer compiler (Scala 2.8 -> internal 5.0) than what most libraries like for example scalatest 1.0 are compiled against (2.7.7 -> internal 4.1).

The remedy is to point your IntelliJ plug-in to the libraries downloaded with the Scala 2.7.7 final installation. As far as I know as of now you have to do this under Project Structure by either clicking on the Project Structure icon or by using Ctrl+Alt+Shift+S and then under Project Settings you select Facets. This should give you a dialog window where you can set the Scala compiler library and the Scala SDK library.

Make sure you did not install on a path with spaces because that would be interpreted as separate paths constructs.

3 comments:

Unknown said...

thank you, this was quite helpful. really starting to get into this. have you played with akka yet?

Unknown said...

Aw mate - that was a beautiful tip. Thanks

MJ said...

The very same error one can get when using e.g. maven-scala-plugin

The remedy for this should be changing the scala version number in your pom.xml