I am starting a new project in Play Framework with Java. I checked the build.sbt
file and couldn't understand where the dependencies names came from?
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
javaJpa
}
Where did these names like javaWs
, javaJpa
, etc. com from? How to check the version of these libraries?
tl;dr They're defined by the sbt-plugin
(see javaWs and javaJpa or others in PlayImport.scala) that's usually added to the build in project/plugins.sbt
.
Use sbt
or activator
tools to learn where the build parts come from. I assume you use sbt
(but the following applies to activator
or play
command line tools, too).
Mind that a sbt build is described using Scala language and all sbt builds are type-safe and compiled using the Scala compiler.
A sbt plugin is just a bunch of settings that can be applied to a project, that can also define Scala val
s that correspond to the different dependencies you can use for a Play project, e.g. javaJdbc
. You can query for the val
s using consoleProject
(that I described below as the second option).
Inside the project, execute sbt
. While in the sbt shell, execute show libraryDependencies
to learn about the dependencies:
> show libraryDependencies
[info] List(org.scala-lang:scala-library:2.11.1, com.typesafe.play:twirl-api:1.0.2, com.typesafe.play:play:2.3.2, com.typesafe.play:play-test:2.3.2:test, com.typesafe.play:play-docs:2.3.2:docs, com.typesafe.play:play-jdbc:2.3.2, com.typesafe.play:anorm:2.3.2, com.typesafe.play:play-cache:2.3.2, com.typesafe.play:play-ws:2.3.2)
Inside the project, execute sbt consoleProject
to learn about the build. I'm using Scala-version of a Play project.
With consoleProject
you enter a Scala REPL with the build loaded. You're in Scala REPL and you can query the different parts of the build using Scala.
Use eval
macro to evaluate build settings inside consoleProject
:
scala> libraryDependencies.eval
res0: Seq[sbt.ModuleID] = List(org.scala-lang:scala-library:2.11.1, com.typesafe.play:twirl-api:1.0.2, com.typesafe.play:play:2.3.2, com.typesafe.play:play-test:2.3.2:test, com.typesafe.play:play-docs:2.3.2:docs, com.typesafe.play:play-jdbc:2.3.2, com.typesafe.play:anorm:2.3.2, com.typesafe.play:play-cache:2.3.2, com.typesafe.play:play-ws:2.3.2)
You get Seq[sbt.ModuleID]
and you can do whatever you want with the value using Scala.
Since build.sbt
for the project looks as follows (I showed only the part with libraryDependencies
):
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws
)
when in consoleProject
I can ask what the names point to as follows:
scala> jdbc
res0: sbt.ModuleID = com.typesafe.play:play-jdbc:2.3.2
Remember, they're Scala val
s of sbt.ModuleID
type and...nothing more than that.
The dependencies listed in this example are the ones that are shipped with your installation of play. The versions match the Play framework version you are using.
Play framework is modular so you don't have to use all of its modules in your application. That is why you must specify which modules you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With