Chapter 6. The IO and Process libraries

 

This chapter covers

  • Creating sbt tasks that run external processes
  • Manipulating files with sbt’s IO library
  • Logging information with sbt’s task loggers
  • Managing the task dependency graph
  • Forking Java processes

So far you’re up and running with sbt and you have a basic build, along with tests to make sure that your code works. But you still have a couple of issues with your build. Your integration tests aren’t quite as slick as you’d like—you still need to start the preowned-kittens application manually. To be fully integrated in your build, you should start the server before running the tests and stop it afterward. You’ll start other processes as well. But before that, you have the problem of packaging. Normally, when you package using sbt, it will create a jar containing just your classes. But you want to package the application into a runnable jar so that it can be deployed to another server for system testing and eventually production. For this you’ll use the built-in sbt IO library. This way, you’re testing what you’ll eventually deploy.

In this chapter, you’ll mainly work in the website/build.sbt file, unless otherwise stated.

6.1. Packaging using processes

In chapter 3 you saw an example of how to use the sbt Process library, the task that retrieved the Git head revision hash:

val gitHeadCommitSha = taskKey[String]("Determines the current git commit
 SHA")
gitHeadCommitSha := Process("git rev-parse HEAD").lines.head

6.2. Packaging using the sbt.IO library

6.3. More mappings

6.4. Task dependencies

6.5. Logging using the sbt logger

6.6. Running your build using fork

6.7. Linking everything together: dependencies

6.8. Linking everything together: processes

6.9. Summary