Play framework 2.2 Slick dependency issue - scala

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

Related

import scalatest shows unresolved even after dumping maven dependency in intellij

I am using intellij 2018 . I have dumped scalatest libraries through build.sbt and I could see libraries in external dependencies in project.
libraryDependencies += "org.scalatest" %% "scalatest" % "3.3.0-SNAP2" % Test
But when I import scalatest library in class it is showing not resolved.
how to make this work ?
import org.scalatest.flatspec.AnyflatSpec

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

Is it possible to use json4s 3.2.11 with Spark 1.3.0?

Spark has a dependency on json4s 3.2.10, but this version has several bugs and I need to use 3.2.11. I added json4s-native 3.2.11 dependency to build.sbt and everything compiled fine. But when I spark-submit my JAR it provides me with 3.2.10.
build.sbt
import sbt.Keys._
name := "sparkapp"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.3.0" % "provided"
libraryDependencies += "org.json4s" %% "json4s-native" % "3.2.11"`
plugins.sbt
logLevel := Level.Warn
resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
App1.scala
import org.apache.spark.SparkConf
import org.apache.spark.rdd.RDD
import org.apache.spark.{Logging, SparkConf, SparkContext}
import org.apache.spark.SparkContext._
object App1 extends Logging {
def main(args: Array[String]) = {
val conf = new SparkConf().setAppName("App1")
val sc = new SparkContext(conf)
println(s"json4s version: ${org.json4s.BuildInfo.version.toString}")
}
}
sbt 0.13.7 + sbt-assembly 0.13.0
Scala 2.10.4
Is there a way to force 3.2.11 version usage?
We ran into a problem similar to the one Necro describes, but downgrading from 3.2.11 to 3.2.10 when building the assembly jar did not resolve it. We ended up solving it (using Spark 1.3.1) by shading the 3.2.11 version in the job assembly jar:
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("org.json4s.**" -> "shaded.json4s.#1").inAll
)
I asked the same question in the Spark User Mailing List, and got two answers how to make it work:
Use spark.driver.userClassPathFirst=true and spark.executor.userClassPathFirst=true options, but it works only in Spark 1.3 and probably will require some other modifications like excluding Scala classes from your build.
Rebuild Spark with json4s 3.2.11 version (you can change it in core/pom.xml)
Both work fine, I prefered the second one.
This is not an answer to your question but this came up when searching for my problem. I was getting a NoSuchMethod exception in formats.emptyValueStrategy.replaceEmpty(value) in json4s's 'render'. The reason was I was building with 3.2.11 but Spark was linking 3.2.10. I downgraded to 3.2.10 and my problem went away. Your question helped me understand what was going on (that Spark was linking a conflicting version of json4s) and I was able to resolve the problem, so thanks.

Scala Playframework 2.2 - HtmlUnit missing

I have a project using Playframework 2.2
I eclipsified it and in my code I write something like this:
import com.gargoylesoftware.htmlunit.WebClient
val client = new WebClient
Eclipse says everything's fine, but when I play run my application I get a following message:
[error] C:\workspace\kwiket\kwiketscala\app\service\parsers\HTMLParser.scala:11: object gargoylesoftware is not a member of package com
[error] import com.gargoylesoftware.htmlunit.WebClient
How could I fix this? What dependencies should I add to my project? Thanks
In the test configuration is HTMLUnit available, but you need it in the compile configuration.
Just update your libraryDependencies in build.sbt:
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"net.sourceforge.htmlunit" % "htmlunit" % "2.13" //found on http://search.maven.org/#artifactdetails%7Cnet.sourceforge.htmlunit%7Chtmlunit%7C2.13%7Cjar section SBT
)
Restart SBT or execute reload.

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