升级 Play/Scala/SBT/jOOQ/HSQLDB 应用程序时出错
Posted
技术标签:
【中文标题】升级 Play/Scala/SBT/jOOQ/HSQLDB 应用程序时出错【英文标题】:Errors while upgrading Play/Scala/SBT/jOOQ/HSQLDB application 【发布时间】:2021-03-25 00:26:19 【问题描述】:我正在尝试升级 play/scala/sbt/jooq/hsqdb 项目的依赖项。 但是当我尝试通过 jOOQ 从 HSQLDB 表生成类时,出现以下错误。
build.sbt
name := "CH07"
version := "1.0"
lazy val `ch07` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.4"
resolvers += "Spy Repository" at "http://files.couchbase.com/maven2"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
"com.github.mumoshu" %% "play2-memcached-play24" % "0.7.0",
"org.hsqldb" % "hsqldb" % "2.5.0",
"org.jooq" % "jooq" % "3.14.4",
"org.jooq" % "jooq-codegen-maven" % "3.14.4",
"org.jooq" % "jooq-meta" % "3.14.4",
"joda-time" % "joda-time" % "2.7",
"com.github.ironfish" %% "akka-persistence-mongo-casbah" % "0.7.6"
)
routesGenerator := InjectedRoutesGenerator
val generateJOOQ = taskKey[Seq[File]]("Generate JooQ classes")
val generateJOOQTask = (baseDirectory, dependencyClasspath in Compile, runner in Compile, streams) map (base, cp, r, s) =>
toError(r.run(
"org.jooq.codegen.GenerationTool",
cp.files,
Array("conf/chapter7.xml"),
s.log))
((base / "app" / "generated") ** "*.scala").get
generateJOOQ <<= generateJOOQTask
libraryDependencies += "com.ning" % "async-http-client" % "1.9.29"
project/plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.6")
//addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")
//used to work with jooq 3.7.1
//addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.3")
project/build.properties
sbt.version=1.4.4
我尝试使用 jOOQ 生成类,但出现错误(但在我升级依赖项之前它曾经可以工作):
与addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.6")
$ sbt -java-home /usr/lib/jvm/jdk-11.0.1 generateJOOQ
[info] welcome to sbt 1.4.4 (Oracle Corporation Java 11.0.1)
[info] loading settings for project ch07-build from plugins.sbt ...
[info] loading project definition from /home/myname/projects/textbook/CH07/project
/home/myname/projects/textbook/CH07/build.sbt:48: error: value map is not a member of (sbt.SettingKey[java.io.File], sbt.TaskKey[sbt.Keys.Classpath], sbt.TaskKey[sbt.ScalaRun], sbt.TaskKey[sbt.Keys.TaskStreams])
val generateJOOQTask = (baseDirectory, dependencyClasspath in Compile, runner in Compile, streams) map (base, cp, r, s) =>
^
/home/myname/projects/textbook/CH07/build.sbt:49: error: not found: value toError
toError(r.run(
^
sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)
那么使用 Play sbt-plugin 2.8.6,我应该如何重写 generateJOOQTask
的代码?
(另外,我不明白为什么 Play sbt-plugin 会与 jOOQ 代码相关?)
与addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")
$ sbt -java-home /usr/lib/jvm/jdk-11.0.1 generateJOOQ
[info] welcome to sbt 1.4.4 (Oracle Corporation Java 11.0.1)
[info] loading settings for project ch07-build from plugins.sbt ...
[info] loading project definition from /home/myname/projects/textbook/CH07/project
[info] Updating
[info] Resolved dependencies
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.typesafe.play:sbt-plugin:2.5.10 (sbtVersion=1.0, scalaVersion=2.12)
[warn]
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading com.typesafe.play:sbt-plugin;sbtVersion=1.0;scalaVersion=2.12:2.5.10
[error] Not found
[error] Not found
[error] not found: https://repo1.maven.org/maven2/com/typesafe/play/sbt-plugin_2.12_1.0/2.5.10/sbt-plugin-2.5.10.pom
[error] not found: /home/myname/.ivy2/local/com.typesafe.play/sbt-plugin/scala_2.12/sbt_1.0/2.5.10/ivys/ivy.xml
[error] not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.play/sbt-plugin/scala_2.12/sbt_1.0/2.5.10/ivys/ivy.xml
[error] not found: https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.play/sbt-plugin/scala_2.12/sbt_1.0/2.5.10/ivys/ivy.xml
[error] at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:258)
[error] at lmcoursier.CoursierDependencyResolution.$anonfun$update$38(CoursierDependencyResolution.scala:227)
[error] at scala.util.Either$LeftProjection.map(Either.scala:573)
[error] at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:227)
[error] at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error] at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:53)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:103)
[error] at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:73)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$20(LibraryManagement.scala:116)
[error] at scala.util.control.Exception$Catch.apply(Exception.scala:228)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:116)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:97)
[error] at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:219)
[error] at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:130)
[error] at sbt.Classpaths$.$anonfun$updateTask0$5(Defaults.scala:3485)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] at sbt.Execute.work(Execute.scala:291)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] at java.base/java.lang.Thread.run(Thread.java:834)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.typesafe.play:sbt-plugin;sbtVersion=1.0;scalaVersion=2.12:2.5.10
[error] Not found
[error] Not found
[error] not found: https://repo1.maven.org/maven2/com/typesafe/play/sbt-plugin_2.12_1.0/2.5.10/sbt-plugin-2.5.10.pom
[error] not found: /home/myname/.ivy2/local/com.typesafe.play/sbt-plugin/scala_2.12/sbt_1.0/2.5.10/ivys/ivy.xml
[error] not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.play/sbt-plugin/scala_2.12/sbt_1.0/2.5.10/ivys/ivy.xml
[error] not found: https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.play/sbt-plugin/scala_2.12/sbt_1.0/2.5.10/ivys/ivy.xml
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)
所以使用 Play sbt-plugin 2.5.10,似乎此时 sbt 尝试下载一个不存在的com.typesafe.play:sbt-plugin
。
我如何知道正确的版本是什么以及如何告诉 sbt 如何找到它? (我在build.sbt
中写的内容不应该足以让智能系统了解该做什么吗?)
【问题讨论】:
你确定这些是你的构建工作以来唯一的变化吗?您的第一个错误似乎与从 0.13 到 1.0 时从 sbt 删除的功能有关 问题是 Play 2.8 只针对 sbt 1.x 发布,而 Play 2.5 不是。这两个错误都源于这种不兼容性——您不能将 Play 2.5 与 sbt 1.x 一起使用(它不存在 -> 未找到),您不能将旧的构建定义与 sbt 1.x 一起使用。 由于类包的重命名,我进行了更多更改,这解决了异常——直到我遇到了这个异常(使用 Play sbt-plugin 2.8.6)。知道如何重写generateJOOQTask
吗?我对sbt的理解很浅,所以我尝试做一些阅读。 sbt 语法/内部结构不直观。
查看***.com/questions/55693890/…,我将把它标记为重复。
这能回答你的问题吗? JOOQ sbt 0.3.16 to 1.2.8 migration
【参考方案1】:
这个
val generateJOOQTask = (baseDirectory, dependencyClasspath in Compile, runner in Compile, streams) map (base, cp, r, s) =>
...
是旧的 sbt 0.13 语法。替换为:
generateJOOQ :=
val base = baseDirectory.value
val cp = dependencyClasspath.in(Compile).value
val r = runner.in(Compile).value
val s = streams.value
...
toError
方法在 sbt 1.x 中被删除,替换为
r.run(...).failed foreach (sys error _.getMessage)
那么,这个:
generateJOOQ <<= generateJOOQTask
已弃用 sbt 0.12 语法。替换为
generateJOOQ := generateJOOQTask.value
(注意,我将它与上面的 val 结合在一起)
【讨论】:
错误:value
只能在任务或设置宏中使用,例如 :=、+=、++=、Def.task 或 Def.setting。 — val base = baseDirectory.value — 也:r.run("org.jooq.codegen.GenerationTool", cp.files, Array("conf/chapter7.xml"), s.log) .failed foreach (sys error _ .getMessage) ((base / "app" / "generated") ** "*.scala").get — 它说:无法解析符号失败
对,需要结合第一个设置。
我认为您可以使用val generateJOOQTask = ...
然后generateJOOQ := generateJOOQTask.value
,或者直接使用generateJOOQ := ...
。无论哪种方式,我都会在“失败”、“foreach”、“getMessage”上收到编译错误。错误消息(在 Intellij 中)是“无法解析符号失败”。是因为sbt版本吗?在 project/build.properties
我有 sbt.version=1.4.4
— 这是决定用于 Intellij 编译的 sbt 版本的原因吗?
不可以,因为.value
宏仅适用于任务和设置,而不适用于定义简单的 val。
这解决了.value
错误,但我仍然在 Intellij 中遇到编译错误:“failed”、“foreach”、“getMessage”上的编译错误。错误消息(在 Intellij 中)是“无法解析符号失败”。我在 build.sbt 中使用的代码可以在这里看到:***.com/a/55697023/784980以上是关于升级 Play/Scala/SBT/jOOQ/HSQLDB 应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章