6

I'm fairly new with ScalaTest, and now that I've got it running with Maven, of course I'd like to have it working well in Eclipse as well. My project is a Java project, but I want to improve my Scala skills by writing the tests with ScalaTest.

I understood it so that I should right-click on my project, say "Configure" and "Add Scala Nature". Doing that, however, makes Eclipse try to compile all my Java files with scalac, giving me a lot of "Scala Problem" entries in the problem list. Of course, not having the Scala nature gives me a lot of "Java Problem" entries in my project for all of my Scala files. How can I add the Scala nature only to src/test/scala?

Cheers

Nik

niklassaers
  • 8,480
  • 20
  • 99
  • 146
  • I think I have an eclipse project which contains a mixture of java and scala files and works just fine ... I might have, and when using maven you should anyway have src/java/main and src/scala/main folders. – Jens Schauder Jun 08 '11 at 12:35
  • 1
    When you have mixed Java/Scala, scalac _must_ be used on both `.java` and `.scala` files, to resolve dependencies, and then javac is run to actually compile the `.java`, with the target directory in the classpath, so it can find the files compiles by scalac. The thing is, scalac running on `.java` files shouldn't cause problems. – Daniel C. Sobral Jun 08 '11 at 14:05
  • @Daniel Thanks for letting me know. Curiously it did, I thought this was because it tried compiling them as scala files, but if it's meant to do this and should go well, I'll enable this again and perhaps open a thread on the errors it gives me – niklassaers Jun 09 '11 at 07:35

1 Answers1

2

Maybe the simplest solution (in your context, i.e. classic Java project, without M2Eclipse and a Maven project) would be to have two separate projects:

  • one with only the Java Nature
  • one with the scala nature for tst.

Since you can link a directory in your second project, you don't have to move the sources of the tests(src/test/scala) from your existing file set.
You only have to exclude src/test/scala from any compilation in the first (Java only) project.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That is indeed a simple solution I had not thought of. :-) I assumed I should be able to mix Java and Scala. I'll give this a whirl and report back :-) – niklassaers Jun 08 '11 at 12:48