0

我尝试在 Bazel 中编译一个 Scala 库。这会导致错误:

error: Symbol 'type <none>.slf4j.Logger' is missing from the classpath.
This symbol is required by 'value com.typesafe.scalalogging.slf4j.Logger.underlying'.
Make sure that type Logger is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'Logger.class' was compiled against an incompatible version of <none>.slf4j.
      logger.warn("Foo")
      ^
one error found
one error found
java.lang.RuntimeException: Build failed
    at io.bazel.rulesscala.scalac.ScalacProcessor.compileScalaSources(ScalacProcessor.java:256)
    at io.bazel.rulesscala.scalac.ScalacProcessor.processRequest(ScalacProcessor.java:76)
    at io.bazel.rulesscala.worker.GenericWorker.runPersistentWorker(GenericWorker.java:45)
    at io.bazel.rulesscala.worker.GenericWorker.run(GenericWorker.java:111)
    at io.bazel.rulesscala.scalac.ScalaCInvoker.main(ScalaCInvoker.java:41)

我的BUILD.bazel样子是这样的:

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")

scala_library(
    name = "foo",
    srcs = [
        "src/main/scala/Foo.scala",
    ],
    deps = [
        "@maven//:com_fasterxml_jackson_core_jackson_core",
        "@maven//:com_fasterxml_jackson_core_jackson_databind",
        "@maven//:com_fasterxml_jackson_module_jackson_module_scala_2_11",
        "@maven//:com_typesafe_scala_logging_scala_logging_api_2_11",
        "@maven//:com_typesafe_scala_logging_scala_logging_slf4j_2_11",
        "@maven//:joda_time_joda_time",
        "@maven//:org_scalaj_scalaj_http_2_11",
    ],
)

根据我的阅读,这个错误通常源于混合 2.x 和 2.y Scala 版本。不过,我一生都无法弄清楚我会在哪里做这件事。

4

1 回答 1

0

必须添加org.sonarsource.sonarlint.core:sonarlint-slf4j-sonar-log:4.8.0.14729为依赖项,因为它想要org.slf4j.Logger.

必须查看源代码才能找到:

import org.slf4j.{ LoggerFactory, Marker, Logger => Underlying }
于 2020-03-11T16:25:25.190 回答