How to find the missing Akka Dependencies? - scala

I write a Scala project managed by SBT and I want to use TestKit package (http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/stream-testkit.html#TestKit).
In order to do it, I have to do the following imports:
import system.dispatcher
import akka.pattern.pipe
The problem is that I have to update build.sbt file in order to "bring" the needed dependencies. I tried to add the following dependency:
"com.typesafe.akka" %% "akka-http-testkit" % 2.4.2
and I still got an error for the lines:
import system.dispatcher
and
val probe = TestProbe()
Can you give me a hint on how to find the needed dependency given an import line?

Try to add:
"com.typesafe.akka" %% "akka-http-testkit" % 2.4.2 % Test
akka-http-teskit is a test library, so you should be adding it to the Test scope.

Related

How to find things and install them with Scala sbt?

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

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

package cats contains object and package with same name: implicits

Heard about the new Cats-Effect library here
http://typelevel.org/blog/2017/05/02/io-monad-for-cats.html
Immidiately added the following line to my ammonite shell predef.sc
interp.load.ivy("org.typelevel" % "cats-core_2.12" % "0.9.0")
interp.load.ivy( "org.typelevel" % "cats-effect_2.12" % "0.1-0848c9b")
Now when I load my ammonite shell. I get error
cmd0.sc:1: package cats contains object and package with same name: implicits
one of them needs to be removed from classpath
import cats.effect.IO
^
Compilation Failed
Googled and found a solution here
Package contains object and package with same name
But I wonder how can I apply the -Yresolve-term-conflict:strategy to the ammonite shell?
I was able to solve it myself. Here are the right imports
interp.load.ivy("org.typelevel" %% "cats" % "0.9.0")
interp.load.ivy( "org.typelevel" % "cats-effect_2.12" % "0.1-0848c9b")
Now everything works fine
# import cats._
import cats._
# import cats.effect.IO
import cats.effect.IO
#

object db is not a member of package play

I'm trying to make my first tests with Scala and with Play framework.
I have installed play 2.2.0, which seems to be the last version, with the standalone package. After that, I've been able to create a new application, compile and run it.
I've tried to start to use Anorm package to access to the database, but I've found a blocking error which I can't find on the docs. I don't know if that means that is so obvious, but after adding:
package controllers
import play.api._
import play.api.mvc._
import play.db.anorm._ //(this is the new line)
object Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
}
It fails with:
object db is not a member of package play
I've seen this:
https://groups.google.com/forum/#!msg/play-framework/RUbmEVsw2rY/UOE5mNs1WjoJ
Where they talk about adding the dependency to jdbc, which seems to be already in my build.sbt.
libraryDependencies ++= Seq(
jdbc,
anorm,
cache
)
I've also found this thread here:
play.db package not found in play 2.1.3
But I can't find a build.scala file on my project. Not using any IDE by now, just play console (run & compile commands).
Thanks a lot!
In fact (as the error explains), there is no package play.db.anorm._ in version 2.2.0. Try use import anorm._ instead.
You need the following libraries
slick
play-jdbc
anorm
This is how my dependencies look like in build.sbt :
libraryDependencies ++= Seq(
"com.typesafe.slick" % "slick_2.10" % "2.1.0",
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41",
"com.typesafe.play" % "play-jdbc_2.10" % "2.4.0-RC1",
cache,
anorm
)
Search for the latest version of library at Maven Central Repository

Play framework 2.2 Slick dependency issue

I'm trying to follow this tutorial, but I get stuck as soon as trying to import necessary packages:
import scala.slick.session.Database
import Database.threadLocalSession
import scala.slick.jdbc.{GetResult, StaticQuery => Q}
I'm getting these errors:
object slick is not a member of package scala
not found: object Database
object slick is not a member of package scala
My SBT dependencies:
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"com.typesafe.slick" %% "slick" % "1.0.1",
"com.typesafe.play" %% "play-slick" % "0.5.0.8"
)
What am I missing here?
I'm running Play Framework 2.2.0, Scala 2.10.3
You probably need to run some of these commands in sbt (in this order):
reload
update
eclipse
(obviously substitute eclipse with whatever IDE you are using, or remove it if you are not using an IDE.)