Scala SBT is not able to download dependencies - scala

I am new to scala and Akka. I have created a new project and below is my build.sbt file.
name := "akka_essentials"
version := "0.1"
scalaVersion := "2.13.4"
val akkaVersion = "2.5.13"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion,
"com.scalatest" %% "scalatest" % "3.0.5"
)
The sbt tool is not able to download dependencies. The error log is as below:
[error] stack trace is suppressed; run 'last update' for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.typesafe.akka:akka-testkit_2.13:2.5.13
[error] Not found
[error] Not found
[error] not found: C:\Users\Anand\.ivy2\local\com.typesafe.akka\akka-testkit_2.13\2.5.13\ivys\ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/typesafe/akka/akka-testkit_2.13/2.5.13/akka-testkit_2.13-2.5.13.pom
[error] Error downloading com.scalatest:scalatest_2.13:3.0.5
[error] Not found
[error] Not found
[error] not found: C:\Users\Anand\.ivy2\local\com.scalatest\scalatest_2.13\3.0.5\ivys\ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/scalatest/scalatest_2.13/3.0.5/scalatest_2.13-3.0.5.pom
[error] Error downloading com.typesafe.akka:akka-actor_2.13:2.5.13
[error] Not found
[error] Not found
[error] not found: C:\Users\Anand\.ivy2\local\com.typesafe.akka\akka-actor_2.13\2.5.13\ivys\ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/typesafe/akka/akka-actor_2.13/2.5.13/akka-actor_2.13-2.5.13.pom
I am very new to scala. I have not defined anything like ivy.xml. I am from java background and generally use gradle.
Please advise to resolve this.

Akka 2.5.13 has not been cross published for Scala 2.13 as you can check on Maven.
The earliest version supporting 2.13 (release, not milestone or RC) is 2.5.23. You can see the version matrix for Actors here.
So you need to use newer Akka or older Scala.
With Scalatest you used wrong organization. It's "org.scalatest" not "com.scalatest".
If you have doubts about dependency resoultion check Maven first.

I did the following changes to make it work:
name := "project"
version := "0.1"
scalaVersion := "2.12.7"
val akkaVersion = "2.5.13"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion
// "com.scalatest" %% "scalatest" % "3.0.5"
)

Related

Compiling a Scala program failing Due to Dependencies not found

I have installed Flink, Scala and sbt
Flink Version: 1.9.1
Scala Version: 2.10.6
Sbt Version: 1.3.7
I made relevant changes in build.sbt.
Compile command is failing
Here is the relevant information.
Any information is greatly appreciated
**Versions Information
[osboxes#osboxes local]$ scala -version
Scala code runner version 2.10.6 -- Copyright 2002-2013, LAMP/EPFL
[osboxes#osboxes local]$ flink --version
Version: 1.9.1, Commit ID: 4d56de8
[osboxes#osboxes readcsvfile]$ sbt -version
sbt version in this project: 1.3.7
sbt script version: 1.3.7
** build.sbt changes
val flinkVersion = "1.9.1"
val flinkDependencies = Seq(
"org.apache.flink" %% "flink-scala" % flinkVersion % "provided",
"org.apache.flink" %% "flink-streaming-scala" % flinkVersion % "provided")
** Compile Errors
sbt:readCsvfile> compile
[info] Updating
[info] Resolved dependencies
[warn]
[warn] Note: Unresolved dependencies path:
[error] stack trace is suppressed; run last update for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading org.apache.flink:flink-streaming-scala_2.13:1.9.1
[error] Not found
[error] Not found
[error] not found: /home/osboxes/.ivy2/local/org.apache.flink/flink-streaming-scala_2.13/1.9.1/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/org/apache/flink/flink-streaming-scala_2.13/1.9.1/flink-streaming-scala_2.13-1.9.1.pom
[error] Error downloading org.apache.flink:flink-scala_2.13:1.9.1
[error] Not found
[error] Not found
[error] not found: /home/osboxes/.ivy2/local/org.apache.flink/flink-scala_2.13/1.9.1/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/org/apache/flink/flink-scala_2.13/1.9.1/flink-scala_2.13-1.9.1.pom
[error] Total time: 4 s, completed Jan 30, 2020 3:59:12 PM
sbt:readCsvfile>
Few points I want to mention here regarding the SBT dependencies issues are:
Please add scalaVersion := "2.12.11" in build.sbt file like this, which includes the Scala version in your SBT dependencies automatically due to this%%.
name := "flink-streaming-demo"
scalaVersion := "2.12.11"
val flinkVersion = "1.10.0"
libraryDependencies += "org.apache.flink" %% "flink-scala" % flinkVersion % "provided"
libraryDependencies += "org.apache.flink" %% "flink-streaming-scala" % flinkVersion % "provided"
If you want Scala version specific SBT dependencies then use % like this:
libraryDependencies += "org.apache.flink" % "flink-scala_2.12" % flinkVersion % "provided"
libraryDependencies += "org.apache.flink" % "flink-streaming-scala_2.12" % flinkVersion % "provided"
In worst case if all these does not work then simply delete or rename these existing .sbt and .ivy2 hidden folder in your system home directory, where your all dependecies and plugins get sotred after downloading from maven central and then refresh/build the SBT project.
SBT dependency format
libraryDependencies += groupID % artifactID % revision % configuration
Meaning of % and %%
%: A method used to construct an Ivy Module ID from the strings you supply.
%%: When used after the groupID, it automatically adds your project’s Scala version (such as _2.12) to the end of the artifact name.
NOTE: To get more details click here.
summing up the comments since perhaps it is a bit hard to know what you should do
In general, if you get an "Unresolved dependencies" error, look at mvnrepository.com, search for your artifact:
https://mvnrepository.com/artifact/org.apache.flink/flink-scala
This tells you (second column) which Scala versions are supported by it. In this case, the library is available for 2.11.x and 2.12.x.
Thus, you have to use a Scala version compatible with that in your build, in build.sbt:
ThisBuild / scalaVersion := "2.12.10"

Failing to resolve dependencies with Cassandra for Spark

I'm using spark-cassandra, with the following dependencies:
scalaVersion := "2.11.8"
resolvers += "Spark Packages Repo" at "https://dl.bintray.com/spark-packages/maven"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "2.0.0",
"org.apache.spark" %% "spark-mllib" % "2.0.0",
"datastax" % "spark-cassandra-connector" % "2.0.0-M3"
)
SBT fails to resolve dependencies. What should I change to make it work?
Error:Error while importing SBT project:<br/>...<br/><pre>[info] Resolving org.scala-sbt#run;0.13.8 ...
...
[error] (*:update) sbt.ResolveException: unresolved dependency: datastax#spark-cassandra-connector;2.0.0-M3: not found
[error] (*:ssExtractDependencies) sbt.ResolveException: unresolved dependency: datastax#spark-cassandra-connector;2.0.0-M3: not found
use libraryDependencies += "com.datastax.spark" % "spark-cassandra-connector_2.11" % "2.0.0-M3", as you are using scala 2.11, this should resolve it
maven central repo

scala error: bad symbolic reference

I was using sbt to compile a scala code, and got the following error message
[error] /user/xyin/Projects/measurement_wspark/src/main/scala/json2csv.scala:41: bad symbolic reference. A signature in DefaultReads.class refers to term time
[error] in package java which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling DefaultReads.class.
[error] val ts = (json \ "RequestTimestamp").validate[String]
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
I was using the play json library to parse json files in my main class. And the content of the build.sbt file is like the following:
name := "json_parser"
version := "1.0"
scalaVersion := "2.10.1"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.1"
resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.4.8"
I am totally new to scala and the play framework. Does anyone has any clue about this problem? Thanks!

SBT - missing dependency

Well, my collaborator run code under build.sbt shown below without any problems while I get:
[error] /.../GameMap.scala:91: value revalidate is not a member of javax.swing.JFrame
[error] frame.revalidate()
[error] ^
[error] /.../GameMap.scala:92: value revalidate is not a member of java.awt.Container
[error] frame.getContentPane.revalidate()
[error] ^
I suspect, something is missing in build.sbt:
scalaVersion := "2.10.4"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
// scalacOptions ++= Seq("-feature")
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.8",
"com.typesafe.akka" %% "akka-cluster" % "2.3.8",
"org.scala-lang" % "scala-swing" % "2.10.4"
)
What is it ?
My guess is that your running Java 6 and your collaborator is running Java 7
This is the Container documentation for java 6, which does not list a revalidate method inherited from Component.
And here is the java 7 documentation, which DOES list a revalidate method being inherited from Component
*The same can be stated for swing

scala Either and akka.dispatch Future missing while compiling

I am trying to create a REST service using Spray Servlet, but does not compile.
Below you can find my build.sbt:
name := "someservice"
version := "0.0.1"
scalaVersion := "2.10.0"
resolvers += "spray repo" at "http://repo.spray.io"
libraryDependencies += "io.spray" % "spray-servlet" % "1.0-M3"
libraryDependencies ++= Seq(
"io.spray" % "spray-servlet" % "1.0-M3",
"io.spray" % "spray-util" % "1.0-M3",
"io.spray" % "spray-http" % "1.1-M7",
"com.typesafe.akka" %% "akka-actor" % "2.1.0",
"org.specs2" %% "specs2" % "1.13" % "test",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" artifacts Artifact("javax.servlet", "jar", "jar")
)
There error I get com 'sbt update compile' is:
[error] bad symbolic reference. A signature in package.class refers to term Either
[error] in package scala which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling
[error] package.class.
[error] bad symbolic reference. A signature in package.class refers to type Future
[error] in package akka.dispatch which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when
[error] compiling package.class.
[error] two errors found
[error]
(compile:compile) Compilation failed
Do I have to add the scala library to the sbt build file as well or am I missing something else?
tld;dr: try replacing 1.0-M3 with 1.1-M7
It looks like the Spray artifacts you're using were compiled against Scala 2.9.2, which is not binary compatible with Scala 2.10. Usually, Scala artifacts contain the Scala binary version in the artifact name, precisely because major Scala versions are not binary compatible.
Later spray-util milestones were compiled against Scala 2.10.0-RC5 (based on the pom), which technically should work.
Solved by using all the same spray versions (1.1-M7) and upgrading to Scala 2.10.1