scala error: bad symbolic reference - scala

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!

Related

Scala SBT is not able to download dependencies

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"
)

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"

Compile error scala project

I'm taking the coursera scala course. I downloaded the sample project, but I can not compile it. Giving me error when I run the console command.
build.sbt:
name := course.value + "-" + assignment.value
scalaVersion := "2.12.4"
scalacOptions ++= Seq("-deprecation")
// grading libraries
libraryDependencies += "junit" % "junit" % "4.10" % Test
// for funsets
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4"
resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases"
// include the common dir
commonSourcePackages += "common"
courseId := "bRPXgjY9EeW6RApRXdjJPw"
Error:
> console
[info] Updating root
[info] Resolved root dependencies
[trace] Stack trace suppressed: run last *:coursierResolution for the full output.
[error] (*:coursierResolution) coursier.ResolutionException: Encountered 1 error(s) in dependency resolution:
[error] org.scalatest:scalatest_2.12:2.2.4:
[error] not found:
[error] /Users/joaonobre/.ivy2/local/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[error] /Users/joaonobre/.sbt/preloaded/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[error] /Users/joaonobre/.sbt/preloaded/org/scalatest/scalatest_2.12/2.2.4/scalatest_2.12-2.2.4.pom
[error] https://repo1.maven.org/maven2/org/scalatest/scalatest_2.12/2.2.4/scalatest_2.12-2.2.4.pom
[error] http://repo.artima.com/releases/org/scalatest/scalatest_2.12/2.2.4/scalatest_2.12-2.2.4.pom
[error] Total time: 1 s, completed Dec 22, 2017 4:16:17 PM
scala -version
Scala code runner version 2.12.4 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.
Any idea how to fix it?
Thanks.
As suggested by #laughedelic, Scala 2.12 does not have scalatest-2.2.4. As a result, sbt cannot find the related scalatest pom file. You can pick any of the versions mentioned here.
For instance, try changing scalaTestDependency version to 3.0.5 in the CommonBuild.scala file
lazy val scalaTestDependency = "org.scalatest" %% "scalatest" % "3.0.5"
Here is the course link (Practice Programming Assignment of Week1)

Spark saving to Cassandra with Scala TTL Option

I use Cassandra Spark connector in Scala.
Here is my sample code that is working to save data to Cassandra.
val data = rdd.map
(f => new CassandraRow(IndexedSeq("pk", "count"), IndexedSeq(f._1, f._2.toString())))
data.saveToCassandra("keyspace", "table")
Then, I try to use TTL. Here is my sample code for adding TTL.
adding import
import com.datastax.spark.connector.writer.{TTLOption, WriteConf}
and adding TTL to saveToCassandra
data.saveToCassandra
("keyspace", "table", writeConf = WriteConf(ttl = TTLOption.constant(604800))
However, when I compiled it, it gets Errors.
Error Messages
[error] bad symbolic reference. A signature in TTLOption.class refers to term streaming
[error] in package org.apache.spark 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 TTLOption.class.
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 4 s, completed Mar 31, 2015 11:55:14 AM
build.sbt
name := "Cassandra"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.2.1"
libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "1.2.1"
libraryDependencies += "com.datastax.spark" % "spark-cassandra-connector_2.10" % "1.2.0-rc2"
Is there problem with my code??
This is a known bug in the current connector relating to a dependency on the
streaming spark libraries.
https://datastax-oss.atlassian.net/browse/SPARKC-113
If this is blocking and you need a workaround you can just include the spark-streaming library as a dependency in the build file.
libraryDependencies += "org.apache.spark" % "spark-streaming_2.10" % "1.2.1"

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