2011-12-18 96 views
7

我是Scala和SBT的新手,我試圖找出如何在我的Play 2.0項目中添加lift-json作爲構建依賴項。升降JSON文件說:添加lift-json作爲Play 2.0項目的構建依賴項

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] 

我有提升的源代碼的副本,但我不知道在哪裏把它。而且我很確定我把這個依賴關係放在了錯誤的地方。有人能指點我正確的方向嗎?

+0

有趣的是你想​​要提升JSON裏面播放2.0。你的推理是什麼?只是好奇。 – andyczerwonka 2012-04-04 04:17:55

+0

那麼,我最終決定使用scala-json(Twitter創建的),但這是因爲我發現與Play一起發佈的JSON庫與其他選項相比很難合作。 – 2012-04-04 14:09:22

+0

我同意,電梯似乎好多了。我還沒有嘗試過Twitter。推特圖書館不會給你什麼?我喜歡Lift case類的處理。 – andyczerwonka 2012-04-04 23:36:34

回答

20

你真的很接近 - 唯一的問題是你的lift-json的版本號是錯誤的。

當您進入Scala + SBT世界時,首先可能會引起混淆的是,軟件包是爲特定版本的Scala構建的。 lift-json的當前版本是2.4-M5。儘管如此,您可能已經看過包名稱,如「lift-json_2.9.1」。這裏的2.9.1是指構建包的Scala版本。當您使用您引用的%%語法時,SBT會自動將您使用的Scala版本添加到軟件包名稱;所以你需要指定的唯一版本號是lift-json。

因此你需要

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

這是

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

只是簡寫(注意一個%和2 %%)。

SBT getting started guide是非常有幫助;首先要弄清楚它是如何工作的(這是一種與Ant或Maven完全不同的方法),但是如果你將會使用它,那麼值得讓你頭腦清醒。

根本不需要Lift源代碼,因爲SBT會下載您需要的所有東西 - 包括源代碼包,因此您的IDE或調試器可以導航到它。