4

I am developing an application in Scala Play 2.5.4. I want to test my database interactions, and am attempting to do so by the method recommended in this page.

The trouble is, I am unable to import the object play.api.db.Databases. I suspect that I may need to add something to my build.sbt file, but since this is part of the Play API, I'm not so sure that this is the case.

There are some things available, but not what is shown in the API doc

Image

Pirate X
  • 3,023
  • 5
  • 33
  • 60
Anon Ymous
  • 88
  • 1
  • 6

2 Answers2

5

Yes, you need to add in your build.sbt file this:

libraryDependencies += jdbc

After that, reload activator and update your dependencies (activator update/sbt update).

Note that after this you will need also to add the jdbc driver of the database you intend to use. See more info in https://www.playframework.com/documentation/2.5.x/ScalaDatabase

Edit

As stated in the comments, this may cause problems with Slick. Unfortunately the classes you need to use are provided by that module, so if this causes you problems, you can try two things:

Salem
  • 12,808
  • 4
  • 34
  • 54
  • Thank you for your response, this worked. I should have said in my original post that I am using the Slick API. [This FAQ](https://www.playframework.com/documentation/2.5.x/PlaySlickFAQ) indicates that the jdbc plugin should not be enabled if you are using Slick for DB access. I hope that this won't manifest itself as some other problem. Again, thanks for your response =) – Anon Ymous Aug 01 '16 at 20:25
  • The second solution works. To disable the conflicting module, the line is `play.modules.disabled += "play.api.db.DBModule"` in application.conf. The Databases object code does not help much because it misses other dependences (ConnectionPool, HikariCPConnectionPool, etc., no idea where they come from). – JulienD Feb 23 '17 at 12:06
0

For people who do not have dependency to Slick but have the same problem. If you have added dependencies to jdbc and your DB driver (for example Postgresql) and problem still exists, reindexing of all dependencies via sbt is required. In my case closing IntelliJ Idea and subsequent reopening project back causes dependencies reindexing and problem was gone.