Anuj Pratap Singh
Anuj Pratap Singh

Reputation: 81

How should one start on creating a sbt plugin?

I want to create a sbt plugin for Scala project.

Please any one suggest me how we start?

I referred Plugins documentation but unable to understand steps.

Upvotes: 7

Views: 2416

Answers (1)

Eugene Yokota
Eugene Yokota

Reputation: 95624

The first step in becoming a sbt plugin author is understanding sbt build definition. The best resource for it is Getting Started guide. For plugins, it's essential that you understand the concept of scoping. Some of my blog posts like an unofficial guide to sbt 0.10 v2.0 and traveling through the 4th dimension with sbt 0.13 discuss the topic.

Next, try reading the source code for existing plugins:

  • sbt/sbt-appengine

    • sbt-appengine adds defines appengineSettings, which the build user can include in his or her build definition to add appengineDeploy and other appengine related tasks.
  • sbt/sbt-man

    • sbt-man on the other hand overrides settings and adds man command.

These are roughly two patterns for plugins. Once you understand them fully, try making your own plugin.

Another source of inspiration is the source for sbt itself. Whenever I'm writing a plugin, I'd consult Defaults.scala to see how sbt implements a particular task that I'm interested in. Once you're comfortable, you should also read Plugins Best Practices too.

Upvotes: 5

Related Questions