Issue importing Akka packages - scala

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.

Related

Sbt assembly for multiple targets

I need to create fat jars for multiple version of scala using sbt assembly.
When I target a single version, I write in simple.sbt:
scalaVersion := "2.11.12"
And the fat jar is output to target/scala-2.11/Kernalytics-assembly-1.0.jar. Now I would like to also target Scala 2.12. I could edit the sbt file to change scalaVersion, but I would like the assembly process to be automated over a range of versions of Scala when I call sbt assembly.
If I use crossScalaVersions:
name := "Kernalytics"
version := "1.0"
crossScalaVersions := Seq("2.11.12", "2.12.4")
libraryDependencies ++= Seq(
"org.scalanlp" %% "breeze" % "0.13.2",
"org.scalanlp" %% "breeze-natives" % "0.13.2",
"org.scalanlp" %% "breeze-viz" % "0.13.2"
)
libraryDependencies += "commons-io" % "commons-io" % "2.6"
resolvers += "Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.4"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test"
The only output is target/scala-2.12/Kernalytics-assembly-1.0.jar
If you use crossScalaVersions I think you need to prefix the command with a '+' if you want to build for all versions.
From Cross-Building a Project:
To build against all versions listed in crossScalaVersions, prefix the action to run with +

Why does sbt give multiple dependencies warning with Akka and ScalaTest dependencies?

I've just added ScalaTest to build.sbt so it now looks as follows:
name := "appname"
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.1",
"org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
)
After that I am receiving the warning message:
SBT project import
[warn] Multiple dependencies with the same organization/name but different versions. To avoid conflict, pick one version:
[warn] * org.scala-lang:scala-reflect:(2.11.2, 2.11.7)
[warn] * org.scala-lang.modules:scala-xml_2.11:(1.0.2, 1.0.4)
I also tried changing the line concerning ScalaTest into:
"org.scalatest" %% "scalatest" % "2.2.4" % "test"
but the warning still remains the same as above.
How could I deal with this issue since I haven't anywhere written "reflect" or "xml" in my project. I am using the newest version of both Akka and ScalaTest and Scala version 2.11.
The solution might be to add explicitly one of proposed versions by SBT. All warnings pass away when libraryDependencies is:
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.1",
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
"org.scala-lang" % "scala-reflect" % "2.11.7",
"org.scala-lang.modules" %% "scala-xml" % "1.0.4"
)
In your particular case this is related to the ISSUE 1933 and you can ignore it for now. You can also explicitly specify version of the dependency you need, to silence warnings.
The problem is fixed with sbt 0.13.12

module not found: io.spray#sbt-revolver;0.7.2 using intellij 14.1.4 with sbt 0.13.5

I have tried many things but cant seem to get this to work.
I have the following in my build.sbt
name := "MyTestApp"
version := "0.1-SNAPSHOT"
scalaVersion := "2.10.3"
resolvers ++= Seq("spray repo" at "http://repo.spray.io",
"Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/",
"Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases",
"Plugin Releases" at
"http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases")
libraryDependencies ++= Seq(
"Io.spray" %% "spray-routing" % "1.3.2",
"io.spray" %% "spray-can" % "1.3.2",
"com.typesafe.akka" %% "akka-actor" % "2.2.3",
"com.typesafe.akka" %% "akka-slf4j" % "2.2.3",
"org.slf4j" % "slf4j-simple" % "1.6.4",
"io.spray" % "sbt-revolver" % "0.7.2"
)
I have also added the following to my plugins.sbt file
addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.2")
I am using scala 2.10 with sbt version 0.13.5
My build log seems to indicate it is trying to resolve at the following location
==== Plugin Releases: tried
[warn] http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/io/spray/sbt-revolver/0.7.2/sbt-revolver-0.7.2.pom
Browsing to the following perhaps it would resolve if it was looking in
http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/io.spray/sbt-revolver/scala_2.10/sbt_0.13/0.7.2/
Any ideas as to why io.spray has turned into io/spray in the url
Any help deeply appreciated
Use this:
Resolver.url("Plugin Releases", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
instead of:
"Plugin Releases" at "http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases"
This sets the correct URL pattern for this repository.

Mllib dependency error

I'm trying to build a very simple scala standalone app using the Mllib, but I get the following error when trying to bulid the program:
Object Mllib is not a member of package org.apache.spark
Then, I realized that I have to add Mllib as dependency as follow :
version := "1"
scalaVersion :="2.10.4"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "1.1.0",
"org.apache.spark" %% "spark-mllib" % "1.1.0"
)
But, here I got an error that says :
unresolved dependency spark-core_2.10.4;1.1.1 : not found
so I had to modify it to
"org.apache.spark" % "spark-core_2.10" % "1.1.1",
But there is still an error that says :
unresolved dependency spark-mllib;1.1.1 : not found
Anyone knows how to add dependency of Mllib in .sbt file?
As #lmm pointed out, you can instead include the libraries as:
libraryDependencies ++= Seq(
"org.apache.spark" % "spark-core_2.10" % "1.1.0",
"org.apache.spark" % "spark-mllib_2.10" % "1.1.0"
)
In sbt %% includes the scala version, and you are building with scala version 2.10.4 whereas the Spark artifacts are published against 2.10 in general.
It should be noted that if you are going to make an assembly jar to deploy your application you may wish to mark spark-core as provided e.g.
libraryDependencies ++= Seq(
"org.apache.spark" % "spark-core_2.10" % "1.1.0" % "provided",
"org.apache.spark" % "spark-mllib_2.10" % "1.1.0"
)
Since the spark-core package will be in the path on executor anyways.
Here is another way to add the dependency to your build.sbt file if you're using the Databricks sbt-spark-package plugin:
sparkComponents ++= Seq("sql","hive", "mllib")

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!