简体   繁体   English

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

[英]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. 我是Scala和SBT的新手,我正在试图弄清楚如何在我的Play 2.0项目中添加lift-json作为构建依赖项。 The lift-json documentation says: lift-json文档说:

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: 我甚至不确定“项目描述”实际存储在哪里,但我找到了一个具有以下内容的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      
    )

}

You can see the line I added for net.liftweb. 你可以看到我为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. 我有一个Lift源代码的副本,但我不知道放在哪里。 And I'm pretty sure I put that dependency in the wrong place. 而且我很确定我把这种依赖放在了错误的地方。 Could someone please point me in the right direction? 有人可以指点我正确的方向吗?

You're really close-- the only problem is that you've got the wrong version number for lift-json. 你真的很接近 - 唯一的问题是你的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. 当你进入Scala + SBT世界时,有一件事可能会令人困惑的是,包是为特定版本的Scala构建的。 The current version of lift-json is 2.4-M5. 目前版本的lift-json是2.4-M5。 Nonetheless you've probably seen package names like "lift-json_2.9.1". 尽管如此,你可能已经看到了像“lift-json_2.9.1”这样的软件包名称。 The 2.9.1 here refers to the version of Scala for which the package was built. 这里的2.9.1指的是构建包的Scala版本。 SBT automatically adds the Scala version you're using to the package name when you use the %% syntax that you quoted; 当您使用引用的%%语法时,SBT会自动将您正在使用的Scala版本添加到包名称中; so the only version number you need to specify is the lift-json one. 所以你需要指定的唯一版本号是lift-json。

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 %%). (注意一个%vs两个%%)。

The SBT getting started guide is very helpful; SBT入门指南非常有帮助; it can be a little intimidating at first to figure out how it works (which is quite a different approach from eg Ant or Maven), but it's worth getting your head around if you'll be using it. 一开始可能会有点吓人,想弄清楚它是如何工作的(这与Ant或Maven的方法完全不同),但是如果你要使用它,那么值得一试。

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

The answer from David is correct, however, I still found it difficult to find the correct version. 大卫的答案是正确的,然而,我仍然发现很难找到正确的版本。 (2.4-M5 got outdated in the mean time) (2.4-M5同时过时)

You should look got the recent builds at: 您应该看看最近的版本:

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

Look for lift-json and the scala version you are using to get the right directory, for me it was: 寻找lift-json和用于获取正确目录的scala版本,对我而言:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM