试图执行编译任务但无法加载神秘模块

Attempting to execute compile task but mystery module can't be loaded

我正在编译一个由多个部分组成的 Scala 项目。它不是那么大,但其中一些是 Scala 2.13,一些是 Scala 3。

尝试编译会产生致命错误 [未解决的相关性: base#base_2.12;0.1.0-SNAPSHOT: 未找到]

事实是,字符串 {0.1.0-SNAPSHOT} 没有出现在我的 build.sbt 或其他任何地方。它曾经在那里,但它早已不复存在了。我假设某些更新缓存包含它,但我一直无法找到它。

这是我的{build.sbt}:

ThisBuild / libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
ThisBuild / Compile / scalacOptions ++= Seq("--deprecation")

ThisBuild / Test / logBuffered := false
ThisBuild / Test / parallelExecution := false

lazy val scala213 = "2.13.5"
lazy val scala212 = "2.12.13"
lazy val scala3 = "3.0.0-RC2"
lazy val supportedScalaVersions = List(scala213, scala3)

lazy val root = (project in file("."))
  .aggregate(top, trans, base)
  .settings(
    name := "toysat"
  )

lazy val top = (project in file("top"))
  .settings(
    name := "main",
    scalaVersion := scala213,
    scalacOptions += "-Ytasty-reader",
    libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
  )
  .dependsOn(trans, base)

lazy val trans = (project in file("trans"))
   .settings(
     name := "trans",
     Compile / scalaVersion := scala3,
     libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
   ).
  dependsOn(base)

lazy val base = (project in file("base"))
  .settings(
    name := "base",
    scalaVersion := scala213,
    libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
   

Whosebug 上的此类问题大多与下载远程定义的模块有关。我遇到的问题是 sbt 找不到我的(新编译的)模块之一的过时版本。

这是 sbt 命令的输出(这是一个 Emacs 缓冲区):

sbt:toysat> reload
[info] welcome to sbt 1.5.5 (AdoptOpenJDK Java 1.8.0_292)
[info] loading project definition from /Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/project
[info] loading settings for project root from build.sbt ...
[info] set current project to toysat (in build file:/Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/)
sbt:toysat> compile
[info] compiling 4 Scala sources to /Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/base/target/scala-2.13/classes ...
[warn] 
[warn]  Note: Unresolved dependencies path:
[info] done compiling
[error] stack trace is suppressed; run last trans / update for the full output
[error] (trans / update) sbt.librarymanagement.ResolveException: Error downloading base:base_2.12:0.1.0-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/drewmcdermott/.ivy2/localbase/base_2.12/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/base/base_2.12/0.1.0-SNAPSHOT/base_2.12-0.1.0-SNAPSHOT.pom
[error] Total time: 25 s, completed Jul 28, 2021 11:06:18 PM

编译 base 子项目中的 4 个文件耗时 25 秒,显然是成功的。我认为是当 sbt 试图编译它遇到麻烦的 trans 子项目时。

这是部分堆栈跟踪。除了涉及 Coursier 之外,这对我来说毫无意义。

sbt:toysat> last trans / update
[debug] not up to date. inChanged = true, force = false
[debug] Updating trans...
[warn] 
[warn]  Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading base:base_2.12:0.1.0-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/drewmcdermott/.ivy2/localbase/base_2.12/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/base/base_2.12/0.1.0-SNAPSHOT/base_2.12-0.1.0-SNAPSHOT.pom
[error]     at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:258)
[error]     at lmcoursier.CoursierDependencyResolution.$anonfun$update(CoursierDependencyResolution.scala:227)
[error]     at lmcoursier.CoursierDependencyResolution$$Lambda62/0x0000000000000000.apply(Unknown Source)
[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(LibraryManagement.scala:59)

似乎很明显某处的某个缓存保留了字符串 0.1.0-SNAPSHOT,但缓存的数量多得惊人。我试过删除几个,但我没有找到相关的。

谁能解释一下如何从这种情况中恢复过来?

您的 base 项目仅针对 Scala 2.13 编译,而它被定义为 trans 的依赖项(使用 dependsOn),目标是 Scala 3。

您应该为 Scala 2.13 和 3 交叉构建您的 base 项目(根据您的错误消息可能是 2.12,即使我没有看到您共享的内容中有任何 Scala 2.12 的使用)。

编辑:Scala 2.13 和 3 是兼容的,因此只有在为 2.12 构建依赖项时才会出现此问题。

我不是因为我是一个自恋者而回答我自己的问题,而是因为我不能在评论中说出我想要的。另外,编辑原始问题会将可能有用的信息隐藏在一个奇怪的地方。我已经投票并批准了@GaelJ 的回答。

我的 build.sbt 看起来没什么不同。可以通过显示修改后的 trans 子项目定义来封装差异:

lazy val trans = (projectMatrix in file("trans"))
   .settings(
     name := "trans",
     version := "0.3",
     // I thought this line was unnecessary, but without 
     // it sbt doesn't understand the command trans / compile --
     Compile / scalaVersion := scala3,
     libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
   )
  .jvmPlatform(scalaVersions = Seq(scala213))
  .dependsOn(base)