I am very interested at using the Scala script engine that we have now in scala 2.11
I saw that within the REPL everything works but if I do it from a test (I tried from sbt and maven) then the ScriptEngine for scala is not found.
I tried that to see which ScriptEngine are present
println("manager:" + manager.getEngineFactories.size())
manager.getEngineFactories.toList.foreach(factory => println(factory.getClass.getSimpleName))
But I only get NashornScriptEngine (I have JDK8)
Does anybody have an idea why I can't find it? I had previously issues with NashornScript in SBT that could be resolved by added fork in Test but this is not the issue here.
It is as if the ScriptEngine is not present in the classpath when you are outside the REPL
Did you add the REPL (and, maybe, the compiler?) to the classpath? I imagine that if you don't specify the dependency and bring only the library, it would definitely not work.
If you did do that, perhaps if you could be more forthcoming with details on how you are doing this test?
Related
I am porting a small legacy library from scala 2.12 to scala 2.13. sbt version is 1.3.3. The project is flat and relatively simple. scalaVersion declared in the project is 2.13.1.
I am executing clean and compile tasks, and then publish to both local ivy and to the artifactory.
The process seemingly goes fine and creates the artifact with the _2.13 suffix. When this binary gets executed against scala 2.13 runtime, it fails with MethodNotFound exception. Further introspection shows that the artifact was compiled for 2.12 but not for 2.13.
Does anybody have an idea why a different compiler version was used by sbt, and how to fix this problem?
Just had similar issue, sbt was compiling my project to the wrong Scala version, found this question without answers in google.
So, my problem was actually very simple. Turns out you need to start sbt in a project root directory (where build.sbt is located). I was running it from a directory where all my .scala files were located, so it haven't parsed build.sbt and compiled project using default Scala version (2.12 in my case).
I'm using Eclipse ScalaIDE and for some reason I'm not able to
import scala.io.StdIn
I'm getting a red squiggly that tells me:
object StdIn is not a member of package io
And I'm seeing that it's not in that scala.io jar file. The ScalaDoc, however says it should be there. I've tried both scala 2.10.4 and 2.11.5. I've used the Eclipse ScalaIDE to create the scala project and I've also created an sbt eclipse project directly using the scalasbt.plugin which I use all the time to manage ScalaIDE dependencies.
sbt "eclipse with-source=true"
Neither way is getting it.
I'm currently taking the Coursera Reactive Programming course and an assignment file has this import. I'm able do compile the project with sbt directly, but Eclipse ScalaIDE is not doing the job. Any clues? There may be good reason why not to use scala.io.StdIn, but my question is why can I not get it to import in the ScalaIDE?
thank you
scala.io.StdIn is new in scala 2.11.x and does not exist in previous versions.
The problem you are likely encountering is that ScalaIDE is not picking up the scala version you are specifying. Since you say that you tried it with 2.10.4, it probably still has that cached or set somewhere and it's failing because it cannot find the specified class.
I've just generated a fresh Play! application, version 2.1-RC1.
This one includes two Scala compiler/library couple:
Scala 2.9.2
Scala 2.10.0-RC1
The whole well compiles within IntelliJ IDEA 12 but a warning occurs as the image shows it:
It would seem so that another compiler is used instead 2.10.0-RC1.
However, my Scala facet is configured as this:
What might be the warning cause?
I precise that I've got also a Scala variable environment (used for shell Scala commands) configured to point to scala-2.10.0-RC2, but I well imagine that IntelliJ is based on library that user indicates in Scala Facet.
You can remove that .jar from the libraries, it's not used because it's redundantly generated by IntelliJ SBT plubin.
I just updated my project to Scala 2.10.0 using SBT 0.12. But now, when running sbt, I get the following error:
java.lang.NoClassDefFoundError: scala/reflect/ManifestFactory$
at X.build.Unidoc$.<init>(Unidoc.scala:8)
at X.build.Unidoc$.<clinit>(Unidoc.scala)
at X.build.ServicesBuild$.<init>(Build.scala:25)
at X.build.ServicesBuild$.<clinit>(Build.scala)
It seems that the problem is on SettingKey:
8: val unidocDirectory = SettingKey[File]("unidoc-directory")
I heard that Scala 2.10 was doing reflects different than before and thought that that was the issue, yet the Akka project is doing the same exact thing and (I assume) they are doing fine.
https://github.com/akka/akka/blob/master/project/Unidoc.scala (my Unidoc.scala is pretty much a copy&paste of theirs).
Does anyone know what is happening? How can it not find a class in scala itself?
Thanks!
I've created Java annotations (since I need run time retention) under $PROJECT/src/main/java and my scala codewhich uses these java annotations us under $PROJECT/src/main/scala. The Java annotation thus created also makes use of a Java ENUM as it's value.
If I compile the project then sbt doesn't seem to compile the Java annotations first and errors out on each usage of the enum in annotations. If I comment out all usages of the Java enum in annotations in scala code and do a compile, uncomment enum usage and compile again it all works fine.
How do I ensure that sbt compiles my java annotations and enum (i.e. $PROJECT/src/main/java) before attempting to compile scala code when doing a clean build?
EDIT: I have a bare bones build.sbt and am using sbt 0.11.2
Some good news: This is a known issue and has been resolved.
Some bad news: It's resolved in 2.10 and the fix may not be backported to 2.9.3 (quoting Paul Phillips in the issue thread):
I've tagged this for backporting, which is not a guarantee; I don't
have time to do it right now but I expect to in the near future.
Some good news: If you're stuck on pre-2.10 and your Java sources don't depend on your Scala sources, you can just add the following to your build.sbt and all is well:
compileOrder := CompileOrder.JavaThenScala
Some bad news: If you're stuck on pre-2.10 and your Java sources do depend on your Scala sources, I'm pretty sure you're out of luck, and the comment-compile-uncomment trick is probably your best bet.
I'll bet you're facing SI-2764. This has been fixed in Scala 2.10.
In the meantime, create a separate sub-project for your Java annotations, and depend on this from the project containing the Scala code.. Then the Scala compiler will only process the .class files, rather the .java files.