Explicitly enable SBT plugin inside another SBT plugin

I am writing an sbt plugin to abstract some of the patterns associated with a few common plugins that I use. In this quest, one of the plugins that I am trying to configure has a value of requires for noTrigger , for which you need to explicitly enable the plugin in the project settings.

With SBT AutoPlugin, if I set requires = BuildInfoPlugin and trigger = allRequirements , then the settings will automatically load if I explicitly enable the base plugin, or if I set trigger = noTrigger as above, then explicitly adding the plugin to which I work on also imports the base plugin.

 /* Requires enablePlugins(BuildInfoPlugin) to be explicitly set on project, then the settings in this plugin will automatically load. */ object BuildInformation extends AutoPlugin { override def requires = BuildInfoPlugin override def trigger = allRequirements } 

.

 /* Requires enablePlugins(BuildInformation) to be explicitly set on project, which will automatically import BuildInfoPlugin */ object BuildInformation extends AutoPlugin { override def requires = BuildInfoPlugin } 

Is there a way for a derivative plugin to explicitly import the underlying plugin without requiring it to be explicitly added to the derived plugin? (For example, the PlayScala plugin from PlayFramework downloads sbt-native-packager and download it, but PlayScala must be explicitly enabled)

One thing that I was thinking about is simply extending the base plugin, and overriding this method launches the allRequirements method, but it was interesting to see if there is a cleaner / more preferable method.

+7
scala sbt
source share
1 answer

Not more elegant than the output, but perhaps more flexible:

 object DerivedPlugin extends AutoPlugin { override def trigger: PluginTrigger = allRequirements override def requires = JvmPlugin val autoImport = BasePlugin.autoImport override lazy val projectSettings = BasePlugin.projectSettings } 
0
source share

All Articles