With the following task declaration in project/Build.scala
, the print
task is not recognised when I type in print
at an SBT console.
lazy val print = task { println("print") }
What's wrong?
Delegate a Scala project build to sbt Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.
The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.
You need a TaskKey
for this to work that can be instantiated by using the taskKey
macro:
lazy val printTask = taskKey[Unit]("print")
I recommend having a look at the corresponding documentation about tasks. The documentation says:
The name of the val is used when referring to the task in Scala code. The string passed to the TaskKey method is used at runtime, such as at the command line
taskKey[Unit]("print") := println("print")
Then in your SBT console,
> print
print
In more complex code, you'll usually see keys separate from the settings.
val printTask = taskKey[Unit]("print")
printTask := println("print")
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