This document contains various references and notes about sbt build definition. One of the motivation for this document is that the official sbt documentation is not very informative.
- Official sbt documentation
- sbt.Keys defines all the tasks and settings keys, including their documentation.
- Get reference to the logger via
streams.value.log
. - Log and error via
streams.value.log.error("My error")
- Note that this will not cause the task to fail, this will only log an
[error]
message. IF you want to fail a task, refer to Fail a task.
- Note that this will not cause the task to fail, this will only log an
- Simply throw a
java.lang.RuntimeException
.- This will always work - it will crash the whole sbt process with the RuntimeException. But it is not the official recommended way.
inspect tree project/assembly
- This prints all the tasks and settings that will be executed when
project / assembly
is run. - It may be helpful to increase the width of the ASCI tree with
set asciiGraphWidth := 150
.
- This prints all the tasks and settings that will be executed when
- See
help inspect
.
print dependencyTree
- This shows all the transitive dependencies for the default
Compile
scope.
- This shows all the transitive dependencies for the default
print Test/dependencyTree
- This show all the transitive dependencies for the
Test
scope.
- This show all the transitive dependencies for the
- There is
--jvm-debug
cmd line option to sbt which allows to attach a debugger to the sbt process.- This option is not very handy, as you will still not be able to add a
breakpoint to various task definitions inside
build.sbt
, only to some classes in theproject
directory. Moreover, once you runreload
, the debugging will not work for sure.- This is because sbt internally compiles everything from
build.sbt
a various anonymous classes and the debugger does not see their sources.
- This is because sbt internally compiles everything from
- This option is not very handy, as you will still not be able to add a
breakpoint to various task definitions inside
- It is better to either use
println
directly, or to usestreams.value.log.info
to log messages.
- Fat jar for
fat-project
is assembled via thefat-project / assembly
task. - There is
fat-project / assembly / assemblyExcludedJars
setting which is of typeDef.ClassPath
. - To exclude internal
project
one must:- Set
project / Compile / exportJars := true
. This ensures thatproject / Compile / exportedProducts
is a path to the jar. - In
fat-project / assembly / assemblyExcludedJars
get the path to theproject
jar viaproject / Compile / exportedProducts
. - Declare dependency on
project / Compile / packageBin
fromfat-project / assembly
.
- Set
- Note that this is complicated because
assemblyExcludedJars
setting only works if it points to an already existing jar file.