Chapter 11. Defining a plugin

 

This chapter covers

  • Getting to know the AutoPlugin interface and using it to make life easier for the user
  • Testing a plugin with sbt scripted
  • Using configurations in your plugin
  • Adding incremental tasks
  • Reusing code using Scala files

In this chapter we’ll go into the nuts and bolts of constructing a plugin. Plugins are the primary vehicle of reuse within sbt. As you saw previously, when you want your build to do something, the first thing to do is look for a plugin. If you don’t find one, go ahead and add the custom functionality. Once you have the functionality working in your own build, sbt plugins provide a means for you to share it with the rest of the sbt ecosystem.

What is a plugin? A plugin is a set of reusable sbt settings that users can include in their build without having to copy/paste them in. Most of the time users should be able to reuse existing settings and tasks and likely tweak a few values here and there for their build. In this chapter we’ll look at how to provide those tasks, along with some recommendations as to how to set up your plugin to make it easy for the end user. You’ll write a simpler version of the Scalastyle plugin that you saw earlier.

11.1. Reusing code using Scala files

11.2. Introducing the AutoPlugin interface

11.3. Testing a plugin with the scripted plugin

11.4. Using configurations in your plugin

11.5. Adding incremental tasks

11.6. Making things easy for the user—more about the AutoPlugin interface

11.7. Summary