|
SbtPlugins
Existing PluginsBasicsPlugins are libraries for your project definition. Declare them like dependencies for your project, except in a plugin definition in the project/plugins/ directory. For example, to use MarkdownJ in your project definition, create: project/plugins/Plugins.scala import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info)
{
val a = "org.markdownj" % "markdownj" % "0.3.0-1.0.2b4"
}Verify it is correct by doing reload and then console-project. Call some MarkdownJ code: scala> new com.petebevin.markdown.MarkdownProcessor res1: com.petebevin.markdown.MarkdownProcessor = Markdown Processor for Java 0.3.0 (compatible with Markdown 1.0.2b2) This dependency was independent of sbt. You can also create and use plugins that extend or use sbt. The rest of this page describes sbt plugins. The first part shows the results of a plugin that creates a self-extracting jar out of a project. The second part shows how to create a simple plugin that provides a new action to a project. Installer Example
Hello World PluginTo try out plugins, we'll make a simple hello world plugin and use it. Make the PluginTo make a plugin, create a new project with a project definition that extends PluginProject. This can now go in project/build. The basic example: import sbt._ class TestPluginProject(info: ProjectInfo) extends PluginProject(info) Make a simple plugin by putting the following in src/main/scala : package hw
import sbt._
trait HelloWorldPlugin extends Project {
lazy val hello = task { log.info("Hello World!"); None }
}Publish it by running the publish-local action. Use the PluginTo use the plugin, create a new project. Declare plugins by putting a plugin definition (basically a project definition that extends PluginDefinition) in project/plugins/. The following example assumes that the plugin above had was setup with the name "test" and with version "1.0". import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
val a = "test" % "test" % "1.0"
}Define the project definition in project/build/ to use the HelloWorldPlugin : import sbt._ class TestProject(info: ProjectInfo) extends DefaultProject(info) with hw.HelloWorldPlugin Try it out by running the hello action at the prompt. |
Sign in to add a comment