Can't resolve casbah as a sbt dependency - mongodb

I'm getting the following error upon compile:
[error] (*:update) sbt.ResolveException: unresolved dependency: org.mongodb#casbah_2.11;2.7.4-SNAPSHOT: not found
With this build.sbt file:
name := """play-scala"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws
)
libraryDependencies += "org.mongodb" %% "casbah" % "2.7.4-SNAPSHOT"
// For stable releases
resolvers += "Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases"
// For SNAPSHOT releases
resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
I'm using Typesafe Activator and have tried many combinations of Casbah versions (including releases, instead of snapshots) and resolvers. The installation instructions from the "official" MongoDB Casbah tutorial don't work either. Any ideas?

If you go to the release and snapshot URLs and try to manually locate casbah, you'll see that the snapshot url doesn't have anything for casbah currently.
On the other hand, the release repo has 2.7.3 for Scala 2.11. Check it out here.
Maybe try
libraryDependencies += "org.mongodb" %% "casbah" % "2.7.3"

use following dependancy in your build.sbt file :
libraryDependencies += "org.mongodb" %% "casbah" % "2.8.1"

use these lib
"org.mongodb" %% "casbah" % "3.1.1",
"org.json4s" %% "json4s-jackson" % "3.5.2",
"org.json4s" %% "json4s-mongo" % "3.5.2"

Related

Manage dependencies with sbt & IntelliJ IDEA

I'm working on a back-end project using for the first time Scala and the Play Framework with IntelliJ IDEA.
I've been reading a lot of documentation and topics:
SBT Library dependencies doc
IntelliJ support post
Another post from stackoverflow
I can't understand how to import dependencies.
When I try to append a new dependency, IntelliJ underlines it and shows either "Unknown artifact. Not resolved or indexed" or a log shows up and says "SBT unknown import".
Every dependency I add is from the Maven Repository.
Here is the build.sbt file:
name := "server"
version := "1.0"
lazy val `server` = (project in file(".")).enablePlugins(PlayScala)
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"
resolvers := ("Atlassian Releases" at "https://maven.atlassian.com/public/") +: resolvers.value
scalaVersion := "2.12.2"
libraryDependencies ++= Seq(
jdbc,
ehcache,
ws,
specs2 % Test,
guice,
"org.mongodb.scala" %% "mongo-scala-driver" % "2.1.0",
"com.mohiva" %% "play-silhouette" % "5.0.2",
"com.mohiva" %% "play-silhouette-password-bcrypt" % "5.0.2",
"com.mohiva" %% "play-silhouette-crypto-jca" % "5.0.2",
"com.mohiva" %% "play-silhouette-persistence" % "5.0.2",
"com.mohiva" %% "play-silhouette-testkit" % "5.0.2" % "test"
)
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
These dependencies were specified using a shorthand that is defined by the Play plugin:
jdbc,
ehcache,
ws,
specs2 % Test,
guice
So for them to work, be sure to include a line like the following in an .sbt file in the project directory:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.10")
That should fix your problem.
Bonus tip: No need for the following lines, and because each additional resolver slows down SBT, you should delete them:
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"
resolvers := ("Atlassian Releases" at "https://maven.atlassian.com/public/") +: resolvers.value

Issue importing Akka packages

I have the following build.sbt file:
name := "akkaHttp"
version := "1.0"
scalaVersion := "2.12.0"
resolvers ++= Seq("Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
Resolver.bintrayRepo("hseeberger", "maven"))
libraryDependencies ++= {
val AkkaVersion = "2.3.9"
val AkkaHttpVersion = "2.0.1"
val Json4sVersion = "3.2.11"
Seq(
"com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
"com.typesafe.akka" %% "akka-http-experimental" % AkkaHttpVersion,
"ch.qos.logback" % "logback-classic" % "1.1.2",
"org.json4s" %% "json4s-native" % Json4sVersion,
"org.json4s" %% "json4s-ext" % Json4sVersion,
"de.heikoseeberger" %% "akka-http-json4s" % "1.4.2"
)
}
In it, these dependencies are not met.
Error:Unresolved dependencies:
com.typesafe.akka#akka-slf4j_2.12;2.3.9: not found
com.typesafe.akka#akka-http-experimental_2.12;2.0.1: not found
org.json4s#json4s-native_2.12;3.2.11: not found
org.json4s#json4s-ext_2.12;3.2.11: not found
de.heikoseeberger#akka-http-json4s_2.12;1.4.2: not found
So what should I add to it such that the imports work?
Notice the _2.12 appended to the artifacts? Based on your scalaVersion, SBT tried to download the dependencies built against Scala 2.12.x, but couldn't find any. Try using Scala version 2.11.8.
Different versions of Scala can be binary incompatible, so libraries are cross built against those different versions and published to the repositories. Looks like it hasn't yet happened for those libraries above.
Note that Scala 2.12 is indeed not binary compatible with Scala 2.11.

Libraries not resolving in sbt within intellij, but resolves and compiles from commandline

The below sbt file doesn't resolve the spark-xml databricks package from within intelliJ Idea where as works fine with command line
name := "dataframes"
version := "1.0"
scalaVersion := "2.11.8"
val sparkVersion="1.4.0"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % sparkVersion % "provided",
"org.apache.spark" %% "spark-sql" % sparkVersion,
"com.databricks" %% "spark-xml" % "0.3.3"
)
resolvers ++= Seq(
"Apache HBase" at "https://repository.apache.org/content/repositories/releases",
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
resolvers += Resolver.mavenLocal
The sbt was set to both bundled and other pointing to the locally installed sbt, but did not work either way.
The below package resolves and works perfectly from commandline
import com.databricks.spark._

Build issues for apache spark

I have been having a sbt dependency issue when I try to build my apache spark project. I have Apache Spark 1.3.1.
My .sbt file is this:
name := "Transaction"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.3.1"
resolvers ++= Seq(
"Akka Repository" at "http://repo.akka.io/releases/",
"Spray Repository" at "http://repo.spray.cc/")
And I keep getting this error:
[error] (*:update) sbt.ResolveException: unresolved dependency: org.apache.spark#spark-core_2.10;1.3.1: not found
I have looked all over and this seems to be a persistent issue, but no one has really solved it.
Thanks for your help!
I used
“org.apache.spark” % “spark-core_2.10” % “1.3.1”
instead of
“org.apache.spark” %% “spark-core” % “1.3.1”
and it worked!
EDIT:
However, I was able to get the latter statement to work after specifically making my scalaVersion 2.10 so:
scalaVersion := "2.10"
Probably because it tries to look for a specific 2.10.4 jar which doesn't exist.
I actually figured it out. You just need to put "provided"after the spark version.
name := "Transaction Fraud"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.3.1" % "provided"
resolvers ++= Seq(
"Akka Repository" at "http://repo.akka.io/releases/",
"Spray Repository" at "http://repo.spray.cc/")

resolviing SBT dependencies

I am new to JVM development (I am using Scala and SBT) and am having trouble resolving dependencies. Yesterday, I had trouble resolving the org.restlet.2.1.1 dependency and today, I am having trouble with resolving the following:
[error] (*:update) sbt.ResolveException: unresolved dependency: com.mongodb.casbah#casbah_2.9.2;2.1.5-1: not found
[error] unresolved dependency: org.scalatra#scalatra_2.9.2;2.3.0: not found
[error] unresolved dependency: org.scalatra#scalatra-akka2_2.9.2;2.3.0: not found
[error] unresolved dependency: org.scalatra#scalatra-specs2_2.9.2;2.3.0: not found
I am using a giter8 scalatra-mongodb project template from github: click me. Since the project is a little old, it stands to reason that I am trying to obtain outdated versions that no longer exist or are compatible. What does one do in this situation? I tried fiddling with the version numbers in my build.sbt file, but this did not work (and appears to be worse!).
The following is the contents of my build.sbt file:
scalaVersion := "2.9.2"
mainClass := Some("JettyLauncher")
seq(webSettings :_*)
port in container.Configuration := 8080
seq(assemblySettings: _*)
libraryDependencies ++= Seq(
"com.mongodb.casbah" %% "casbah" % "2.8.1-1",
"org.scalatra" %% "scalatra" % "2.2.0",
"org.scalatra" %% "scalatra-akka2" % "2.2.0",
"org.scalatra" %% "scalatra-specs2" % "2.2.0" % "test",
"org.mortbay.jetty" % "servlet-api" % "3.0.20100224" % "provided",
"org.eclipse.jetty" % "jetty-server" % "8.0.0.M3" % "container, compile",
"org.eclipse.jetty" % "jetty-util" % "8.0.0.M3" % "container, compile",
"org.eclipse.jetty" % "jetty-webapp" % "8.0.0.M3" % "container, compile"
)
resolvers ++= Seq(
"Sonatype OSS" at "http://oss.sonatype.org/content/repositories/releases/",
"Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
"Akka Repo" at "http://akka.io/repository/",
"Web plugin repo" at "http://siasia.github.com/maven2"
)
The following is my plugins.sbt file:
addSbtPlugin("com.earldouglas" %% "xsbt-web-plugin" % "0.9.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
Note that when I first generated the template, I was receiving missing dependencies for this first plugin. Fortunately, the github page for this plugin gave updated instructions and I am able to get past this dependency.
Anyway, what are the versions of these dependencies that I need to get everything working? In general what is a strategy for resolving these dependencies (right now I have no idea what to do (other than visit the github pages and fiddle with version numbers)?
Thanks for all the help!
I have at least gotten sbt to resolve my dependencies for whatever that is worth (it has classpath issues now...). Anyway, the following is my new and improved build.sbt file:
scalaVersion := "2.10.4"
mainClass := Some("JettyLauncher")
seq(webSettings :_*)
port in container.Configuration := 8080
seq(assemblySettings: _*)
libraryDependencies += "org.mongodb" %% "casbah-core" % "2.7.3"
libraryDependencies += "org.scalatra" %% "scalatra" % "2.2.0-RC3" cross CrossVersion.binary
libraryDependencies += "org.scalatra" %% "scalatra-akka" % "2.2.0-RC3"
libraryDependencies += "org.scalatra" %% "scalatra-specs2" % "2.2.0" % "test"
libraryDependencies += "org.mortbay.jetty" % "servlet-api" % "3.0.20100224" % "provided"
libraryDependencies += "org.eclipse.jetty" % "jetty-server" % "9.0.0.M5" % "container"
libraryDependencies += "org.eclipse.jetty" % "jetty-util" % "9.0.0.M5" % "container"
libraryDependencies += "org.eclipse.jetty" % "jetty-webapp" % "9.0.0.M5" % "container"
resolvers ++= Seq(
"Sonatype releases" at "http://oss.sonatype.org/content/repositories/releases/",
"Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
"Akka Repo" at "http://akka.io/repository/",
"Web plugin repo" at "http://siasia.github.com/maven2"
)
All I really did was spend a few hours googling and searching mvn repositories that were compatible with the scala version I am using (2.10.4). I learned that %% will append the scala-version to the dependency name (seems like a nice convention since Scala is always evolving). Once, I got a few dependencies resolved, the rest caved!