playframework 2.0 scala - No suitable driver found in tests - scala

I was following this tutorial to star using playframework2.1 RC1 + Slick.
When try launch the SoftwareSpec test (that tests Model-like class):
play test
they fail with an error like this:
[error] SQLException: No suitable driver found for
jdbc:h2:mem:test1 (DriverManager.java:190) [error]
SoftwareSpec$$anonfun$1$$anonfun$apply$3.apply(SoftwareSpec.scala:25)
[error]
SoftwareSpec$$anonfun$1$$anonfun$apply$3.apply(SoftwareSpec.scala:25)
But I've enabled h2 db in application.conf like was mentioned in that article.
I've used latest dependencies to slick, in Build.scala file:
"com.typesafe" % "slick_2.10.0-RC1" % "1.0.0-RC1"
Once, when I changed dependency to slick to this version:
"com.typesafe" % "slick_2.10.0-RC1" % "0.11.2"
then the test was passed successfully. But after I change the test to make it fail, the error came back again - "No suitable driver". And after this all my tries (like play clean whatever) were unsuccessful.

I got the same error when running tests on Travis CI.
A work around is loading JDBC driver class like Class.forName("org.h2.Driver").
https://github.com/seratch/scalikejdbc/blob/564cc07505d7a9f217945a7f2c07dc2c7460ed87/scalikejdbc-play-plugin/src/test/scala/scalikejdbc/PlayPluginSpec.scala#L15
Of course, I should investigate the reason of this issue and report to the Play team but I haven't done.

I'm not using Play at the moment, so I can't test the following, but it should be fine. For the latest Slick, you can use:
"com.typesafe" % "slick_2.10" % "1.0.0-RC1"
For h2, the following should work:
"com.h2database" % "h2" % "1.3.166"

Related

Why doesn't Scalavista see the dependencies set in build.sbt?

Scalavista, or Scala Syntax (official) - these are the Scala extensions I have.
I have in build.sbt e.g.
, "org.scalatra" %% "scalatra-json" % "latest.integration"
and when I write
import org.scalatra.json._
then it marks it as an error and says object scalatra is not a member of package org. And it's just one example, my code is full of red waves. And that's only in vscode; when I run the program from sbt, it compiles and works OK.
Shouldn't it be aware of the dependencies?
You should install the sbt-scalavista SBT plugin in order to let it generate the scalavista config for your project.

getting NoClassDefFoundError using elastic4s

I'm using play 2.6 and scala 2.12 in my app, and elastic search using elastic4s.
In my build.sbt:
"com.sksamuel.elastic4s" %% "elastic4s-core" % "5.6.0",
"com.sksamuel.elastic4s" %% "elastic4s-http" % "5.6.0",
and I keep getting this exception in my log:
Exception in thread "I/O dispatcher 16" java.lang.NoClassDefFoundError: Could not initialize class com.sksamuel.elastic4s.http.JacksonSupport$
at com.sksamuel.elastic4s.http.ResponseHandler$.fromEntity(ResponseHandler.scala:47)
at com.sksamuel.elastic4s.http.DefaultResponseHandler.$anonfun$onResponse$1(ResponseHandler.scala:55)
at scala.util.Try$.apply(Try.scala:209)
at com.sksamuel.elastic4s.http.DefaultResponseHandler.onResponse(ResponseHandler.scala:55)
at com.sksamuel.elastic4s.http.HttpExecutable$RichRestClient$$anon$1.onSuccess(HttpExecutable.scala:27)
at org.elasticsearch.client.RestClient$FailureTrackingResponseListener.onSuccess(RestClient.java:597)
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:352)
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:343)
at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:119)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:177)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:436)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:326)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
at java.lang.Thread.run(Thread.java:748)
Trying to figure out what could cause this.
In another log also saw:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.8.8 requires Jackson Databind version >= 2.8.0 and < 2.9.0
so it looks like something with the jackson version, or also with the jackson version, but not sure where do I update it or where is it failing exactly...
Someone ever had this issue?
thanks!
Double check if you are importing elastic4s-jackson:
libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s-jackson" % "5.6.0"
I have had the exact same issue with play 2.8 and elastic4s 6.7.3 using the jackson module too
What helped me was running evicted and looking at the dependencies each library had and figuring out why it cannot load that particular class . ultimately upgrading to 6.7.8 ended up resolving the issue.
Also if you look in the buid.sbt file for the elasic4s project it lists all the versions it is using https://github.com/sksamuel/elastic4s/blob/master/build.sbt
You can use jackson-module-scala and exclude the com.fasterxml.jackson which is referenced in elastic4s-http and verify that com.fasterxml.jackson is available in the libraries/classpath when the application is running.

Error: value seq is not a member of object slick.dbio.DBIO

I am writing a web application in play framework. I decided to use slick (FRM) to query in my database (postgre). I am new to slick so I started following slick official document for revision 3.0.0
http://slick.typesafe.com/doc/3.0.0/gettingstarted.html
As per the documentation, I added dependencies in my build.sbt file
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.0.0",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
Everything else is working fine but while writing below line in my Scala IDE. It is showing error that
value seq is not a member of object slick.dbio.DBIO
val setup = DBIO.seq(
// Above line is showing error
(suppliers.schema ++ coffees.schema).create,
.
.
.
)
In fact Scala IDE (same as eclipse IDE) isn't detecting any member of object DBIO though when I browse slick api of same version http://slick.typesafe.com/doc/3.0.0/api/#slick.dbio.DBIO$ for object DBIO I am seeing seq as it's member.
Where am I doing wrong?
As anticipated by retronym and Chris Scot, this problem was fixed with the release of Slick 3.1
You need to import the API for the database you are using:
import slick.driver.PostgresDriver.api._
I'm not sure if you've got your answer (I'm answering for those that may stumble upon this in the future), but I've resolved this by upgrading to 3.0.0-M1 and using Action.seq() instead of DBIO.seq()
This may also work in 3.0.0, but I'm not sure as I upgraded from Slick 2.x to 3.0.0-M1!

Why don't specs2 + scalamock tests run in IntelliJ? Multiple suite traits detected

I'm trying to run Specs2 tests from IDEA from both Windows and Mac versions of Intellij IDEA 14. I generated the idea project files using both gen-idea and the built in SBT plugin and get the same results...
When I try to run them, I get
Error running Specs2 in 'scala': Test class not found
I've added packages and switched "search for tests" to in single module but still no avail. I also get the message below on the run config.
Multiple suite traits detected: List(ScTrait: SpecificationStructure, ScTrait: SpecificationStructure,)
The similar post How to run all Specs2 tests under IntelliJ IDEA? doesn't help and it all runs fine from SBT, BTW. I can't run individual tests via the short-cut either :'(
I'm suspecting it's a combination of scalamock and specs2, as if I remove the following from my build.sbt, I can run them again.
"org.scalamock" %% "scalamock-specs2-support" % "3.2" % "test"
Here's the run config.
You should check if you have multiple specs2 jars dependencies in your module. If you just leave one jar dependency the configuration error should disappear.
To help other googlers, it could also be that you have one package depending on specs2-core, and scalamock-specs2-support which depends on specs2. The solution is to add an explicit dependency on specs2, and both dependencies should be evicted to the one you import. I was just able to fix this with the following dependency: "org.specs2" %% "specs2" % "3.7" % "test"

sbt submit gives "not a valid command" error

Trying to submit my assignments. Looks easy from the demo, but receiving weird error. SBT version is correct. What may be wrong?
> sbt-version
[info] 0.12.4
> submit
[error] Not a valid command: submit (similar: set)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: submit
You need to be using the code package for the course downloaded from the Coursera course web site, otherwise there will be no submit command available as it's not a built-in of SBT or Scala or anything. This is also covered by the tutorial video lecture, and you will be able to obtain the link from the course site.
Also, you need to provide your e-mail address and submission key (which you can obtain from the course web site) as parameters to the submit command.
yes, I watched all the videos... but imported the example incorrectly :)
To correctly import the example, you need to run sbt in the folder with the build.sbt file. In my case, the scalatest version was not found. To fix, it could be updated to (in CommonBuild.scala):
lazy val scalaTestDependency = "org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test