添加lift-json作为Play 2.0项目的构建依赖项

时间:2011-12-18 00:21:06

标签: scala playframework sbt

我是Scala和SBT的新手,我正在试图弄清楚如何在我的Play 2.0项目中添加lift-json作为构建依赖项。 lift-json文档说:

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

我甚至不确定“项目描述”实际存储在哪里,但我发现了一个具有以下内容的Build.scala:

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      
    )

}

您可以看到我为net.liftweb添加的行。不幸的是,这似乎是错误的地方或错误的内容,因为我得到以下构建错误:

[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]

我有一个Lift源代码的副本,但我不知道放在哪里。而且我很确定我把这种依赖放在了错误的地方。有人可以指出我正确的方向吗?

2 个答案:

答案 0 :(得分:20)

你真的很接近 - 唯一的问题是你的lift-json版本号错了。

当您进入Scala + SBT世界时,最初可能会令人困惑的一件事是,针对特定版本的Scala构建了包。目前版本的lift-json是2.4-M5。尽管如此,你可能已经看到了像“lift-json_2.9.1”这样的软件包名称。这里的2.9.1指的是构建包的Scala版本。当您使用引用的%%语法时,SBT会自动将您正在使用的Scala版本添加到包名称中;所以你需要指定的唯一版本号是lift-json one。

因此你需要

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

这只是

的简写
"net.liftweb" % "lift-json_2.9.1" % "2.4-M5"

(注意一个%vs两个%%)。

SBT getting started guide非常有用;一开始就弄清楚它是如何起作用的有点吓人(这与Ant或Maven的方法完全不同),但是如果你要使用它,那么值得你好好理解。

您根本不需要Lift源代码,因为SBT将下载您需要的所有内容 - 包括源包,因此您的IDE或调试器可以导航到它。

答案 1 :(得分:1)

大卫的答案是正确的,然而,我仍然发现很难找到正确的版本。 (2.4-M5同时过时)

你应该看看最近的版本:

http://repo1.maven.org/maven2/net/liftweb/

查找lift-json以及用于获取正确目录的scala版本,对我而言:

http://repo1.maven.org/maven2/net/liftweb/lift-json_2.11/