Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add lift-json as build dependency for Play 2.0 project

I'm new to Scala and SBT, and I'm trying to figure out how to add lift-json as a build dependency in my Play 2.0 project. The lift-json documentation says:

Add dependency to your project description:
val lift_json = "net.liftweb" %% "lift-json" % "XXX"

I'm not sure even where the "project description" is actually stored, but I found a Build.scala that has the following:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "test"
    val appVersion      = "1.0"

    val appDependencies = Seq(
      // Add your project dependencies here,
      "net.liftweb" %% "lift-json" % "2.9.1"
    )

    val main = PlayProject(appName, appVersion, appDependencies).settings(defaultScalaSettings:_*).settings(
      // Add your own project settings here      
    )

}

You can see the line I added for net.liftweb. Unfortunately, that appears to be the wrong place, or wrong content, because I get the following build error:

[info] Updating {file:/D:/play/test/}test...
[warn]  module not found: net.liftweb#lift-json_2.9.1;2.9.1
[warn] ==== local: tried
[warn]   D:\play\play-2.0-beta\framework\..\repository/local/net.liftweb/lift-json_2.9.1/2.9.1/ivys/ivy.xml
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   D:\play\play-2.0-beta\framework\..\repository/local/net.liftweb/lift-json_2.9.1/2.9.1/jars/lift-json_2.9.1.jar
[warn] ==== Play Repository: tried
[warn]   http://download.playframework.org/ivy-releases/net.liftweb/lift-json_2.9.1/2.9.1/ivys/ivy.xml
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://download.playframework.org/ivy-releases/net.liftweb/lift-json_2.9.1/2.9.1/jars/lift-json_2.9.1.jar
[warn] ==== Typesafe Repository: tried
[warn]   http://repo.typesafe.com/typesafe/releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.pom
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://repo.typesafe.com/typesafe/releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.jar
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.pom
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://repo1.maven.org/maven2/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.jar
[warn] ==== Scala-Tools Maven2 Repository: tried
[warn]   http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.pom
[warn]   -- artifact net.liftweb#lift-json_2.9.1;2.9.1!lift-json_2.9.1.jar:
[warn]   http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.9.1/2.9.1/lift-json_2.9.1-2.9.1.jar
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: net.liftweb#lift-json_2.9.1;2.9.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[error] {file:/D:/play/test/}test/*:update: sbt.ResolveException: unresolved dependency: net.liftweb#lift-json_2.9.1;2.9
.1: not found
[error] application -

! @68mcpckf2 - Internal server error, for request [GET /] ->

play.api.UnexpectedException: Unexpected exception [ResolveException: unresolved dependency: net.liftweb#lift-json_2.9.1
;2.9.1: not found]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1$$anonfun$apply$36.apply(SbtPlugin.scala:518) ~[play_2.9.1.jar:na]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1$$anonfun$apply$36.apply(SbtPlugin.scala:511) ~[play_2.9.1.jar:na]
        at scala.Option.map(Option.scala:133) [scala-library.jar:na]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1.apply(SbtPlugin.scala:511) ~[play_2.9.1.jar:na]
        at sbt.PlayProject$$anon$1$$anonfun$reload$1.apply(SbtPlugin.scala:510) ~[play_2.9.1.jar:na]
        at scala.Either$LeftProjection.map(Either.scala:183) ~[scala-library.jar:na]
Caused by: sbt.ResolveException: unresolved dependency: net.liftweb#lift-json_2.9.1;2.9.1: not found
        at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:216) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:130) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:129) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:110) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:110) ~[ivy_2.9.1-0.11.0.jar:na]
        at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:98) ~[ivy_2.9.1-0.11.0.jar:na]

I have a copy of the Lift source code, but I don't know where to put it. And I'm pretty sure I put that dependency in the wrong place. Could someone please point me in the right direction?

like image 526
Ben Dilts Avatar asked Dec 18 '11 00:12

Ben Dilts


1 Answers

You're really close-- the only problem is that you've got the wrong version number for lift-json.

One thing that can be confusing at first when you get into the Scala + SBT world is that packages are built for specific versions of Scala. The current version of lift-json is 2.4-M5. Nonetheless you've probably seen package names like "lift-json_2.9.1". The 2.9.1 here refers to the version of Scala for which the package was built. SBT automatically adds the Scala version you're using to the package name when you use the %% syntax that you quoted; so the only version number you need to specify is the lift-json one.

Thus you need

"net.liftweb" %% "lift-json" % "2.4-M5"

which is just shorthand for

"net.liftweb" % "lift-json_2.9.1" % "2.4-M5"

(note one % vs two %%).

The SBT getting started guide is very helpful; it can be a little intimidating at first to figure out how it works (which is quite a different approach from e.g. Ant or Maven), but it's worth getting your head around if you'll be using it.

You won't need the Lift source code at all, as SBT will download everything you need-- including a source package, so your IDE or debugger can navigate to it.

like image 159
David Soergel Avatar answered Nov 16 '22 23:11

David Soergel