AutoPlugin
An AutoPlugin defines a group of settings and the conditions where the settings are automatically added to a build (called "activation"). The requires
and trigger
methods together define the conditions, and a method like projectSettings
defines the settings to add.
Steps for plugin authors:
- Determine if the
AutoPlugin
should automatically be activated when all requirements are met, or should be opt-in. - Determine the
AutoPlugin
s that, when present (or absent), act as the requirements for theAutoPlugin
. - Determine the settings/configurations to that the
AutoPlugin
injects when activated. - Determine the keys and other names to be automatically imported to
*.sbt
scripts.
For example, the following will automatically add the settings in projectSettings
to a project that has both the Web
and Javascript
plugins enabled.
object MyPlugin extends sbt.AutoPlugin {
override def requires = Web && Javascript
override def trigger = allRequirements
override def projectSettings = Seq(...)
object autoImport {
lazy val obfuscate = taskKey[Seq[File]]("Obfuscates the source.")
}
}
Steps for users:
- Add dependencies on plugins in
project/plugins.sbt
as usual withaddSbtPlugin
- Add key plugins to projects, which will automatically select the plugin + dependent plugin settings to add for those projects.
- Exclude plugins, if desired.
For example, given plugins Web and Javascript (perhaps provided by plugins added with addSbtPlugin
),
myProject.enablePlugins(Web && Javascript)
will activate MyPlugin
defined above and have its settings automatically added. If the user instead defines
myProject.enablePlugins(Web && Javascript).disablePlugins(MyPlugin)
then the MyPlugin
settings (and anything that activates only when MyPlugin
is activated) will not be added.
Attributes
- Graph
-
- Supertypes