在简单的 Scala 项目中对 json4s-native 进行着色时出错:"Symbol 'term org.json4s' is missing from the classpath."

Error when shading json4s-native in simple Scala project: "Symbol 'term org.json4s' is missing from the classpath."

我有一个简单的 Scala 项目,我想在使用 sbt-assembly 编译我的胖 JAR 之前遮蔽 json4s-native。我的想法是,在我自己的代码中,我将按如下方式导入带阴影的 Java 类。

import acme.shade.org.json4s.native.Json
...

我尝试使用以下简化的 build.sbt(受 this 启发)。我的想法是创建一个依赖于 json4s-native 的空项目,遮蔽 类,然后让我的实际项目依赖于包含遮蔽 类.

的 JAR
val commonSettings = Seq(
  organization := "com.acme",
  version := "1.0.0",
  scalaVersion := "2.11.12",
  test in assembly := {}
)

// Inspiration for shading JARs taken from:
// https://github.com/wsargent/shade-with-sbt-assembly/
lazy val shaded = (project in file("shaded/libs"))
  .settings(commonSettings)
  .settings(
    name := "my-shaded-lib",
    libraryDependencies ++= Seq(
      "org.json4s" %% "json4s-native" % "3.7.0-M2"
    )
  )
  .settings(
    assemblyOption in assembly ~= { _.copy(includeScala = false) },
    assemblyJarName in assembly := s"my-shaded-lib-${version.value}.jar",
    assemblyShadeRules in assembly := Seq(
      ShadeRule.rename("org.json4s.**" -> "acme.shade.@0").inAll
    )
  )

lazy val root = (project in file ("."))
  .settings(commonSettings)
  .settings(
    name := "shadejson4s",
    mainClass in assembly := Some("com.acme.test.Main"),
    unmanagedJars in Compile ++= Seq(
      shaded.base / "target" / s"scala-${scalaBinaryVersion.value}" / s"my-shaded-lib-${version.value}.jar"
    ),
    update := (update dependsOn (shaded / assembly)).value
  )

包含阴影 类 的 JAR 已成功组装,但是当我尝试编译我的源代码时,出现以下错误:

[info] Compiling 1 Scala source to /private/tmp/shade-json4s/target/scala-2.11/classes ...
[error] /private/tmp/shade-json4s/src/main/scala/com/acme/shadejson4s/Main.scala:3:8: Symbol 'term org.json4s' is missing from the classpath.
[error] This symbol is required by ' <none>'.
[error] Make sure that term json4s is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'package.class' was compiled against an incompatible version of org.
[error] import acme.shade.org.json4s.native.Json
[error]        ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed Feb 11, 2020 2:51:01 PM

我在这里错过了什么?

据我所知,Scala 库不能被遮蔽:https://contributors.scala-lang.org/t/scala-signature-layout/3327