I am trying to use the isEqual method in ScalaMeta.
import scala.meta.contrib._
q"true".isEqual(q"true")
The import does not work:
object contrib is not a member of package meta
I am using sbt and I have the following in my build.sbt
libraryDependencies += "org.scalameta" %% "scalameta" % "4.0.0"
Where can I find the isEqual method for ScalaMeta? It appears to have been deprecated. I am following this tutorial
To get access to Scalameta Contrib you can add the following dependency:
libraryDependencies += "org.scalameta" %% "contrib" % "4.0.0"
isEqual will be accessible, but q isn't. You can import it from scala.meta._.
The corrected example:
import scala.meta._
import scala.meta.contrib._
q"true".isEqual(q"true")
Related
I am trying to call .par on a Scala vector version 2.13.2 but get the error
Error:(1, 25) object parallel is not a member of package collection
import scala.collection.parallel.CollectionConverters._
I have imported
import scala.collection.parallel.CollectionConverters._
and have also added the dependency
libraryDependencies += "org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0"
What's wrong?
I am new to Scala and struggling with sbt and installing things. For example:
I want to develop in Eclipse and hence use JUnit. According to:
http://www.scalatest.org/user_guide/using_junit_runner
"ScalaTest includes a JUnit Runner", that does not seem to be the case. At least not for me. (I get object is not a member of package org.scalatest when I try import org.scalatest.junit.JUnitRunner but import org.scalatest.flatspec.AnyFlatSpec works fine)
How do I install it? I looked at my sbt file, containing the lines:
libraryDependencies += "org.scalactic" %% "scalactic" % "3.1.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.1" % "test"
and thought OK so I need org.scalatest.junit and tried to add it like:
libraryDependencies += "org.scalatest" %% "junit" % "3.1.1"
which of course gave me three(!) screens of:
Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.scalatest:junit_2.12:3.1.1
[error] Not found
(Why is it so repetitive? It's only one thing it hasn't found but it complains about it like four times!)
How do I figure out how to install things like this? Right now I am trying a combined approach of guesswork and random googling, sometimes it works and sometime (like now) it fails for me...
In ScalaTest 3.1.x to execute ScalaTest's suites using JUnit runner add the following dependencies to build.sbt
libraryDependencies ++= List(
"org.scalatest" %% "scalatest" % "3.1.1" % Test,
"org.scalatestplus" %% "scalatestplus-junit" % "1.0.0-M2" % Test
)
and annotate the suite like so
import org.junit.runner.RunWith
import org.scalatestplus.junit.JUnitRunner
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
#RunWith(classOf[JUnitRunner])
class HelloSpec extends AnyFlatSpec with Matchers {
"The Hello object" should "say hello" in {
Hello.greeting shouldEqual "hello"
}
}
There exists an open issue to update the documentation: Document how to use JUnitRunner in 3.x #1780
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
I am doing the Scala course on coursera. I am trying to run the unit tests given in the exercise. However, I am getting the following issues:
Error:(3, 12) object scalatest is not a member of package org
import org.scalatest.FunSuite
^
Error:(6, 12) object junit is not a member of package org
import org.junit.runner.RunWith
^
These appear when I am importing packages into my project:
import org.scalatest.FunSuite
import org.junit.runner.RunWith
I googled this and found the following solution:
Add dependencies like this
libraryDependencies += "com.novocode" % "junit-interface" % "0.8" % "test->default"
I tried adding this code to build.sbt but the errors persist.
ScalaTest is not JUnit. Adding the junit-interface is needed if you want to execute JUnit tests directly with sbt. Obviously you are trying to run ScalaTest tests, though. The additional library dependency you need here is
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.5" % "test"
And then to include JUnit (instead of the junit-sbt-interface), probably this:
libraryDependencies += "junit" % "junit" % "4.12" % "test"
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.