sie*_*kov 6 java jvm scala bazel
我是 Bazel 的初学者,我需要从sbt. 我使用Scala 规则来构建我的应用程序。
我使用具有以下别名的以下依赖项(以防止拼写错误):
| 别名 | 团体 | 神器 | 版本 |
|---|---|---|---|
borer_core |
io.bullet |
borer-core_2.12 |
1.6.3 |
borer_derivation |
io.bullet |
borer-derivation_2.12 |
1.6.3 |
scala_logging |
com.typesafe.scala-logging |
scala-logging_2.12 |
3.9.2 |
logback |
ch.qos.logback |
logback-classic |
1.2.3 |
tagging |
com.softwaremill.common |
tagging_2.12 |
2.2.1 |
ujson |
com.lihaoyi |
ujson_2.12 |
1.2.2 |
所有这些依赖项都将由JVM 外部规则安装。它看起来像这样Workspace:
dp_deps = [
borer_core,
borer_derivation,
scala_logging,
logback,
tagging,
ujson,
]
maven_install(
name = "maven",
artifacts = dp_deps,
repositories = ["http://repo1.maven.org/maven/"],
fetch_sources = True
)
Run Code Online (Sandbox Code Playgroud)
然后我尝试在我的文件中jar使用scala_library构建一个BUILD。看起来是这样的:
scala_library(
name = "some_lib",
srcs = glob(["some_lib/src/main/**/*.scala"]),
unused_dependency_checker_mode = 'warn',
deps = [
"@maven//:io_bullet_borer_core_2_12",
"@maven//:io_bullet_borer_derivation_2_12",
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
"@maven//:ch_qos_logback_logback_classic",
"@maven//:com_softwaremill_common_tagging_2_12",
"@maven//:com_lihaoyi_ujson_2_12"
]
)
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用以下命令构建它:
dp_deps = [
borer_core,
borer_derivation,
scala_logging,
logback,
tagging,
ujson,
]
maven_install(
name = "maven",
artifacts = dp_deps,
repositories = ["http://repo1.maven.org/maven/"],
fetch_sources = True
)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误日志:错误:
ERROR: /Users/<edited>/test-dir/BUILD.bazel:136:14: scala //test-dir:some_lib failed: Worker process did not return a WorkResponse:
Run Code Online (Sandbox Code Playgroud)
日志:
---8<---8<--- Start of log snippet, file at /private/var/tmp/_bazel_<edited>/07059176926c1842b8d4e633b0ddf1f4/bazel-workers/worker-7-Scalac.log ---8<---8<---
[... truncated ...]
scala.tools.nsc.typechecker.Macros$MacroExpander.expand(Macros.scala:622)
at scala.tools.nsc.typechecker.Macros$MacroExpander.apply(Macros.scala:609)
at scala.tools.nsc.typechecker.Macros.standardMacroExpand(Macros.scala:784)
at scala.tools.nsc.typechecker.Macros.standardMacroExpand$(Macros.scala:782)
at scala.tools.nsc.Global$$anon$4.standardMacroExpand(Global.scala:480)
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:457)
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:454)
at scala.tools.nsc.typechecker.AnalyzerPlugins.invoke(AnalyzerPlugins.scala:411)
at scala.tools.nsc.typechecker.AnalyzerPlugins.pluginsMacroExpand(AnalyzerPlugins.scala:454)
at scala.tools.nsc.typechecker.AnalyzerPlugins.pluginsMacroExpand$(AnalyzerPlugins.scala:454)
at scala.tools.nsc.Global$$anon$4.pluginsMacroExpand(Global.scala:480)
at scala.tools.nsc.typechecker.Macros.macroExpand(Macros.scala:773)
at scala.tools.nsc.typechecker.Macros.macroExpand$(Macros.scala:766)
at scala.tools.nsc.Global$$anon$4.macroExpand(Global.scala:480)
at scala.tools.nsc.typechecker.Typers$Typer.vanillaAdapt$1(Typers.scala:1164)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1227)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1200)
at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1220)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5747)
at scala.tools.nsc.typechecker.Typers$Typer.typedValDefImpl(Typers.scala:5949)
at scala.tools.nsc.typechecker.Typers$Typer.typedValDef(Typers.scala:2056)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5651)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5733)
at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:5797)
at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3357)
at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3357)
at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:2017)
at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1883)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5654)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5733)
at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:5797)
at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3357)
at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3357)
at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5363)
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5656)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5733)
at scala.tools.nsc.typechecker.Analyzer$typerFactory$TyperPhase.apply(Analyzer.scala:115)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:451)
at scala.tools.nsc.typechecker.Analyzer$typerFactory$TyperPhase.run(Analyzer.scala:104)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1501)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1485)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1478)
at scala.tools.nsc.Global$Run.compile(Global.scala:1604)
at scala.tools.nsc.Driver.doCompile(Driver.scala:47)
at scala.tools.nsc.MainClass.doCompile(Main.scala:32)
at scala.tools.nsc.Driver.process(Driver.scala:67)
at io.bazel.rulesscala.scalac.ScalacWorker.compileScalaSources(ScalacWorker.java:226)
at io.bazel.rulesscala.scalac.ScalacWorker.work(ScalacWorker.java:70)
at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:92)
at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:46)
at io.bazel.rulesscala.scalac.ScalacWorker.main(ScalacWorker.java:37)
Caused by: java.lang.ClassNotFoundException: io.bullet.borer.deriver.Deriver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 75 more
---8<---8<--- End of log snippet, 2207 chars omitted ---8<---8<---
Target //test-dir:some_lib failed to build
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?的io.bullet.borer.deriver.Deriver是依赖和类路径,但JVM没有看到它。无法记录沙箱的类路径,因为 bazel 无法获取WorkerResponce. 请帮我 。
我已经找到问题了。默认scala_toolchain有direct模式。因此它只看到在ordeps字段中定义的依赖项。因此有两种选择可以解决这个问题:scala_libraryscala_macro_library
因此,对于当前的示例,我们需要定义所有直接依赖项。顺便说一句,当您这样做时它们已经下载了maven_install。现在我们只需要引用它们:
对于borer其他依赖项将是:
@maven//:io_bullet_borer_deriver_2_12因为scala_logging我们需要添加:
@maven//:org_slf4j_slf4j_api因为ujson我们需要:
@maven//:com_lihaoyi_geny_2_12@maven//:com_lihaoyi_upickle_core_2_12Github 示例存储库的所有修复都可以在fix分支下的存储库中找到。