Casbah Scala Runtime Error - scala

I have a Play framework based webapp which has the following defined in its build.sbt file:
....
version := "1.0-SNAPSHOT"
resolvers += "Sonatype Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Sonatype Releases" at "https://oss.sonatype.org/content/groups/scala-tools"
resolvers += "Novus Releases" at "http://repo.novus.com/releases/"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"com.mongodb.casbah" % "casbah_2.9.0" % "2.2.0-SNAPSHOT",
"com.novus" %% "salat-core" % "1.9.2",
"org.scalatest" % "scalatest_2.10" % "2.0" % "test",
"com.typesafe" % "config" % "1.0.2"
)
....
The Scala version is 2.10.3 and when I try to run a unit test, I run into the following error:
A needed class was not found. This could be due to an error in your runpath. Missing class: scala/reflect/ClassManifest
java.lang.NoClassDefFoundError: scala/reflect/ClassManifest
at com.mongodb.casbah.Imports$.<init>(Implicits.scala:113)
at com.mongodb.casbah.Imports$.<clinit>(Implicits.scala)
at com.mongodb.casbah.MongoConnection.apply(MongoConnection.scala:177)
........
........
I'm completely clueless as to why this is happening? Which additional library is that I'm missing?

You can't mix major scala versions (see, casbah artifact is compiled against scala 2.9.*, whereas scala_test is for 2.10.*, and you're saying you use 2.10 in intellij).
The error says, that compiler can't find class that was cut out from scala library since 2.9.* times and solution is to pick proper scala version (any 2.10.* will fit).

Salat author here. The solution is to fix your deps. The latest stable release of Salat is 1.9.4, and it depends on Casbah 2.6.4 - both are available for 2.9 and 2.10.

Instead of using the casbah driver directly for play I have fallen back into using a plugin called play-salat (https://github.com/leon/play-salat).
The one I use at the moment is "se.radley" % "play-plugins-salat_2.10" % "1.3.0" and works well in Play 2.2.

Related

can`t import kamon-play-26 using SBT

I updated my play to 2.6.0. I have a kamon dependency but sbt can't resolve this dependency.
Did anyone encounter this problem too?
Below is my libraryDependencies in the build.sbt:
libraryDependencies +=
Seq(
ws,
"com.google.inject" % "guice" % "3.0",
"com.typesafe.play" %% "play-json" % "2.6.0",
"io.kamon" %% "kamon-play-26" % "0.6.7"
)
But I get a below error as kamon-play-26 not found...
Kamon for Play 2.6 is available for Scala 2.11 and 2.12 with:
"io.kamon" %% "kamon-play-2.6" % "0.6.8"
Note the period in 2.6.
Searching through the kamon repositories in maven reveals that there is no kamon-play-26 package.
The github page https://github.com/kamon-io/kamon-play indicates that it does exist however. Perhaps its been pulled because the build is failing. Compile your own package from source, perhaps?

Can compile with 2.11.2, but not 2.11.3

build.sbt file:
name := "Bag"
version := "0.7.252"
scalaVersion := "2.11.3"
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.11" % "2.1.3" % "test",
"org.scala-lang.modules" %% "scala-swing" % "1.0.1",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"
)
The project compile properly with 2.11.2, but on 2.11.3 I get this.
Scala 2.11.3 is not yet officially released, although as you have witnessed, the artifact was already pushed to Maven Central.
I think that version will be "pulled" because of a binary incompatibility bug introduced in collections. See SI-8899 and SI-8900. Stick to 2.11.2 until a new version (2.11.4?) will be announced.
I'm not sure I understand what is going on in your case, reading the pastbin, but I suggest you open another ticket unless it clearly stems from either of these two issues.
Scala 2.11.3 is not officially released and not recommend. If you want to read the whole story see this.
Scala 2.11.4 should be used instead.

How to declare dependency on Play's Anorm for a standalone application?

What is the current sbt syntax for using a recent version (say, 2.3 or 2.4) of Play's anorm package in standalone mode (not part of a Play application)?
In build.sbt:
resolvers ++= Seq(
"Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/")
libraryDependencies ++= Seq(
"com.typesafe.play" %% "anorm" % "2.3.6")
See example.
Anorm is now published as follows with no need for an additional resolver.
"org.playframework.anorm" %% "anorm" % "2.6.2"

sbt disagreeing with library about scala version

I'm trying to use scala-time with scala 2.10, and have found that it doesn't work with sbt correctly.
given something like
scalaVersion := "2.10.2"
libraryDependencies += "org.scalaj" %% "scalaj-time" % "0.7"
sbt will happily try to resolve http://repo1.maven.org/maven2/org/scalaj/scalaj-time_2.10/0.7/scalaj-time_2.10-0.7.pom.
Unfortunately, scalaj-time is publised with full scala versions as can be seen at http://central.maven.org/maven2/org/scalaj/.
It can be resolved with
libraryDependencies += "org.scalaj" % "scalaj-time_2.10.2" % "0.7"
but I'm wanting to know if this is a change in sbt behaviour, a bug in scala-time's build or if there's a way to configure sbt to pass the 3-part version instead of 2-part.
As Seth noted jorgeortiz85/scala-time likely was published using sbt that predates binary cross versioning convention that was introduced in sbt 0.12. You could do:
libraryDependencies += "org.scalaj" % "scalaj-time_2.10.2" % "0.7"
or
libraryDependencies += "org.scalaj" % "scalaj-time" % "0.7" cross CrossVersion.full
But then you'd be stuck with using 2.10.2 while Scala 2.10.4 is already out.
There's a similar Joda time wrapper named nscala-time/nscala-time that seems more actively maintained. Last updated 3 days ago and Scala 2.11.0 is supported already, so that could also be your option.
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "1.0.0"

Akka migration from 2.0 to 2.1

I have started working with Actors, and was following a simple example as mention in the Getting Started Guide.
Specs:
Scala Version: 2.9.2
Akka Version: 2.0
I ran the example and it ran well. Then I changed by sbt build script to:
name := "PracAkka"
scalaVersion := "2.9.2"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.1.2"
i.e. I started using Akka 2.1.2. There were small changes and as per the migration guide, I made the respective changes. But still I am getting the below error:
class file needed by Props is missing. reference type ClassTag of package reflect refers to nonexisting symbol.
What do I need to change?
The documentation is quite clear I'd say: http://doc.akka.io/docs/akka/2.1.2/project/migration-guide-2.0.x-2.1.x.html
(I.e. Akka 2.1.x is for Scala 2.10)
From the sbt documentation
If you use groupID %% artifactID % revision rather than groupID %
artifactID % revision (the difference is the double %% after the
groupID), sbt will add your project's Scala version to the artifact
name. This is just a shortcut. You could write this without the %%:
libraryDependencies += "org.scala-tools" % "scala-stm_2.9.1" % "0.3"
Assuming the scalaVersion for your build is 2.9.1, the following is
identical:
libraryDependencies += "org.scala-tools" %% "scala-stm" % "0.3"
The idea is that many dependencies are compiled for multiple Scala
versions, and you'd like to get the one that matches your project.
Your script seems to be getting Akka for scala 2.10 in "akka-actor_2.10" try renaming to your scala version.