Scala parsing package isn't recognized - eclipse

I try to import the scala.util.parsing library and the Eclipse compiler doesn't recognize it.
How can I fix it?

scala.util.parsing was removed from the standard library in Scala 2.11. Add this to your dependencies:
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"

Use this version if you're using Scala 2.13:
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"
The imports are the same, so you can use import scala.util.parsing.json._ for example.
See here for all the published versions of this lib.

Related

libraryDependencies Spark in build.sbt error (IntelliJ)

I am trying to learning Scala with Spark. I am following a tutorial but I am having an error, when I try to import the library dependencies of Spark:
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.3"
I am getting the following error:
And I have 3 Unkwons artifacts.
What could be the problem here?
My code is so simple, it is just a Hello World.
Probably you need to add to your build.sbt:
resolvers += "spark-core" at "https://mvnrepository.com/artifact/org.apache.spark/spark-core"
Please note that this library is supported only for Scala 2.11 and Scala 2.12.

Intellij Scala classpath not found

I am trying to use json4s but I keep getting the error below when I compile. I thought the library would have the class internally. I am using json4s-ast_2.11-4.0.0-M1.jar, json4s-core_2.12.3.5.3.jar and json4s-jackson_2.9.1-3.0.0.jar.
Error:(64, 25) Symbol 'type org.json4s.JsonAST.JValue' is missing from the classpath.
This symbol is required by 'type org.json4s.JValue'.
Make sure that type JValue is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'package.class' was compiled against an incompatible version of org.json4s.JsonAST.
Imports:
import org.json4s.jackson.JsonMethods._
import org.json4s._
build.sbt
scalaVersion := "2.12.4"
libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.0.0"
libraryDependencies += "org.json4s" %% "json4s-ast" % "4.0.0-M1"
libraryDependencies += "org.json4s" %% "json4s-core" % "3.5.3"
You can't use libraries compiled for different versions of scala in other versions. You need to fix the versioning of your JSON4s. Look at:
http://www.scala-sbt.org/0.13/docs/Cross-Build.html#Using+Cross-Built+Libraries

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?

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"

Casbah Scala Runtime Error

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.