Wednesday, June 7, 2023

SBT cheat sheet

To see the dependency tree, run:

sbt compile:dependencyTree

(see the answer of 13/12/21 on this SO question)

You might want to tell SBT to use wider margins if it truncatest the tree. Do that with [SO]:

val defaultWidth = 40
val maxColumn = math.max(JLine.usingTerminal(_.getWidth), defaultWidth) - 8

To coax a dependency from Scala 2 to 3, use something like this:

  libraryDependencies ++= List( ("io.laserdisc" %% "fs2-aws-s3" % "5.0.2").withCrossVersion(CrossVersion.for3Use2_13) )

To use the classpath of a particular module, use something like this [see SO]:

sbt "project core" console

In this particular case, we're opening a REPL with the classpath of a given module.

Use versionScheme (SBT docs) if you're writing libraries. This hints at how to handle clashing dependencies. Otherwise, you might see errors when depending on other libraries that "can be overridden using libraryDependencySchemes or evictionErrorLevel" [Scala-Lang]

One last thing: SBT tests run in parallel by default. This can ruin integration tests so you might want to try this workaround [SO] to ensure your tests run serialized.

No comments:

Post a Comment