Intellij Scala classpath not found - scala

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

Related

FunSuite missing even though ScalaTest is imported

I want to start writing simple tests in Scala using ScalaTest.
But for some reason, I can access org.scalatest but not org.scalatest.FunSuite
This is what my build.sbt looks like:
name := "Algorithms"
version := "0.1"
scalaVersion := "2.13.3"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0" % "test"
I don't understand if it can access scalatest then why are FunSuite,FlatSpec and other styles missing?
Output of running test on sbt shell
[error] <Project Path>\Algorithms\src\test\scala\Course1\Week1\MaxPairProductTest.scala:3:48: type FunSuite is not a member of package org.scalatest
[error] class MaxPairProductTest extends org.scalatest.FunSuite {
[error] ^
ScalaTest 3.2.0 has completed modularisation of the monolith from prior versions
The main change in ScalaTest 3.2.0 is carrying out the modularization
that we prepared for in 3.0.8 and 3.1.0. As a result, many deprecated
names have been removed, because the deprecations would cross module
boundaries.
This means that whilst in 3.1.0 the following definition
import org.scalatest.FunSuite
class ExampleSuite310 extends FunSuite {}
would just raise deprecation notice
The org.scalatest.FunSuite trait has been moved and renamed. Please use org.scalatest.funsuite.AnyFunSuite instead. This can be rewritten automatically with autofix: https://github.com/scalatest/autofix/tree/master/3.1.x", "3.1.0"
in 3.2.0 it has been removed entirely. Hence from 3.2.0 onwards you should define like so
import org.scalatest.funsuite.AnyFunSuite
class ExampleSuite320 extends AnyFunSuite {}
See deprecations expirations for full list of new names.
Note we can still import a single artifact which will pull transitively all the sub-artifacts
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0" % "test"
however now we also have the options of depenending on just the particular sub-artifact
libraryDependencies += "org.scalatest" %% "scalatest-funsuite" % "3.2.0" % "test"

object mockito is not a member of package org

Relatively new to sbt and Mockito.
I want to use Mockito in tests, but I'm getting errors related to the Mockito imports when I compile the tests
Imports in test file:
import org.scalatest._
import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar
sbt file:
name := "blah"
version := "0.1"
scalaVersion := "2.13.0"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"
libraryDependencies += "org.mockito" % "mockito-core" % "1.8.5" % "test"
I get these error messages when the tests (fail to) compile:
object mockito is not a member of package org [error] import org.mockito.Mockito._
and also:
Symbol 'type org.mockito.MockSettings' is missing from the classpath.
[error] This symbol is required by 'value org.scalatest.mockito.MockitoSugar.mockSettings'.
I've had a play around with changing some of the versions of scalatest and mockito in the sbt file, but not really if that's getting at the root of the problem or not.
Thanks for any help!
You're using a very old version of Mockito, which is older than the one Scalates relies on, you probably need some 2.x.x version.
On the other hand, I'd recomend you to go fo mockito-scala rather than mockito-core and skip the Scalatest provided classes altogether as they are quite basic.
I suspect you have a caching problem. This happens especially with Intellij.
Here 2 ideas:
Reload the sbt project. See https://stackoverflow.com/a/20466144/2750966
Close the project / delete .idea an open the project newly with Intellij.
Let me know if it is not related with Intellij

IntelliJ: scalac bad symbolic reference

In my build.sbt file I have this in my project.
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.3.1"
libraryDependencies += "org.apache.spark" % "spark-hive_2.10" % "1.3.1"
libraryDependencies += "org.apache.spark" % "spark-graphx_2.10" % "1.3.1"
libraryDependencies += "org.apache.spark" % "spark-mllib_2.10" % "1.3.1"
I just let it download all the libraries automatically. I'm adding graphx, the spark-core, and the scala sdk to one of my project modules but when I try to compile I'm getting:
Error:scalac: bad symbolic reference. A signature in RDD.class refers to term hadoop
in package org.apache which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling RDD.class.
Error:scalac: bad symbolic reference. A signature in RDD.class refers to term io
in value org.apache.hadoop which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling RDD.class.
Error:scalac: bad symbolic reference. A signature in RDD.class refers to term compress
in value org.apache.io which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling RDD.class.
The weird thing is if I download graphx/mllib directly from the maven repositories it seems to compile. Any ideas?
Another possible source of error is the incorrect scalac version setting in the project. Right click project -> Open module settings -> Global Libraries, change/add the scala-sdk version appropriate to your project
Please add the hadoop dependency. Something like
libraryDependencies += "org.apache.hadoop" %% "hadoop-common" % "2.7.1"
libraryDependencies += "org.apache.hadoop" %% "hadoop-hdfs" % "2.7.1"
You may need to add other hadoop modules depending on your app.

Can't use imports inside sbt build definition code

I tried importing JSON libraries in sbt, so that my custom sbt task can write a json file using a JSON api. However it seems like sbt can't import those libraries, but rather it can only import "standard" libraries like scala.io.Source, java.io.File, etc...
Both commented out lines below would each fail sbt:
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.3.7"
libraryDependencies += "io.argonaut" %% "argonaut" % "6.0.4"
compile in Compile <<= (compile in Compile) map { c =>
import scala.io.Source
//import play.api.libs.json.Json
//import argonaut._, Argonaut._
What might it be? Must I write a plugin to circumvent this?
$ about
[info] This is sbt 0.13.6
[info] The current project is built against Scala 2.11.6
[info] Available Plugins: ...
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
Of course I can just string interpolate my json bare-handed but I wonder what might it be...
Thanks!
According to this snippet from the plugin documentation, you just need to include the dependency in plugins.sbt instead of your build definition (ie., no plugin is required).
// [within plugins.sbt]
// plain library (not an sbt plugin) for use in the build definition
libraryDependencies += "org.example" % "utilities" % "1.3"
So you should be able to just add these to plugins.sbt:
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.3.7"
libraryDependencies += "io.argonaut" %% "argonaut" % "6.0.4"

Scala parsing package isn't recognized

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.