I am a beginner in Bazel and I need to migrate from sbt
. I use Scala Rules to build my app.
I use the following dependencies with following aliases (to prevent typos):
Alias | Group | Artifact | Version |
---|---|---|---|
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 |
All these dependencies will be installed by JVM External Rules. It looks like so in 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
)
Then I try to build a jar
with scala_library in my BUILD
file. It looks so:
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"
]
)
Then I try to build it with the following command:
bazel build //test-dir:some_lib --verbose_failures
and I receive the following Error with Log: Error:
ERROR: /Users/<edited>/test-dir/BUILD.bazel:136:14: scala //test-dir:some_lib failed: Worker process did not return a WorkResponse:
Log:
---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
How can I resolve this error? The io.bullet.borer.deriver.Deriver
is in dependencies and classpath but JVM doesn't see it. Cannot log classpath of the sandbox, because bazel cannot get WorkerResponce
. Please help me 😅.
I have found the problem. Default scala_toolchain
has direct
mode. So it sees only dependencies, that are defined in the deps
filed of scala_library
or scala_macro_library
. So there are two options to solve this problem:
deps
array.scala_toolchain
- docs - example
So for the current example, we need to define all direct dependencies. By the way, they are already downloaded when you do maven_install
. Now we need only reference them:
For borer
additional dependencies will be:
@maven//:io_bullet_borer_deriver_2_12
For scala_logging
we need to add:
@maven//:org_slf4j_slf4j_api
And for ujson
we need:
@maven//:com_lihaoyi_geny_2_12
@maven//:com_lihaoyi_upickle_core_2_12
All fixes for the Github example repository are available in the repository under fix
branches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With