gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 09:32:50 28 4
gpt4 key购买 nike

我是 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 源代码的副本,但我不知道把它放在哪里。而且我很确定我把这种依赖放在了错误的地方。有人可以指出我正确的方向吗?

最佳答案

你真的很接近——唯一的问题是你得到了错误的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"

(注意 1% 与 2%%)。

SBT getting started guide非常有帮助;一开始弄清楚它是如何工作的可能有点令人生畏(这与 Ant 或 Maven 等方法完全不同),但是如果您要使用它,则值得考虑一下。

您根本不需要 Lift 源代码,因为 SBT 会下载您需要的一切——包括源包,以便您的 IDE 或调试器可以导航到它。

关于scala - 添加 Lift-json 作为 Play 2.0 项目的构建依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8548952/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com