How to develop sbt plugin in multi-project build with projects that use it?

Is it possible to build the sbt plugin in a multi-project setup and use this plugin in some other subproject of the same multiproject?

For instance:

root/ + mySbtPlugin/ + myProject/ + project/ + plugins.sbt // Uses `mySbtPlugin` 
+2
source share
1 answer

This is not because the only way to define plugins for one or more modules is through project (meta) build. Again, I was deceived to have a solution for you when I set up the sandbox environment with the description that you described.

sbt allows the project project (meta) to be located only in the root directory. No other project directories are processed and become part of the assembly definition.

That's why your best (and only) bet is to create a multi-module assembly for myProject and mySbtPlugin , to facilitate your development and enable the plugin only for those projects that you really want (nevertheless, be careful with auto-plugins .

Project /plugins.sbt

 lazy val root = (project in file(".")) dependsOn sbtNonamePlugin lazy val sbtNonamePlugin = ProjectRef(file("../sbt-noname"), "sbt-noname") addSbtPlugin("pl.japila" % "sbt-noname" % "1.0") 

build.sbt

 lazy val `my-project`, `sbt-noname` = project 

SBT-Noname / build.sbt

 sbtPlugin := true name := "sbt-noname" organization := "pl.japila" version := "1.0" 

SBT-Noname / SRC / Primary / scala / sbtnoname / Plugin.scala

 package sbtnoname import sbt._ import plugins._ object Plugin extends AutoPlugin { override def trigger = allRequirements override val projectSettings: Seq[Setting[_]] = inConfig(Test)(baseNonameSettings) lazy val sayHello = taskKey[Unit]("Say hello") lazy val baseNonameSettings: Seq[sbt.Def.Setting[_]] = Seq( sayHello := { println("I'm the plugin to say hello") } ) } 

With the above files, run sbt .

 > about [info] This is sbt 0.13.6-SNAPSHOT [info] The current project is {file:/Users/jacek/sandbox/multi-plugin/}my-project 0.1-SNAPSHOT [info] The current project is built against Scala 2.10.4 [info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbtnoname.Plugin, com.timushev.sbt.updates.UpdatesPlugin [info] sbt, sbt plugins, and build definitions are using Scala 2.10.4 > projects [info] In file:/Users/jacek/sandbox/multi-plugin/ [info] * multi-plugin [info] my-project [info] sbt-noname > plugins In file:/Users/jacek/sandbox/multi-plugin/ sbt.plugins.IvyPlugin: enabled in multi-plugin, sbt-noname, my-project sbt.plugins.JvmPlugin: enabled in multi-plugin, sbt-noname, my-project sbt.plugins.CorePlugin: enabled in multi-plugin, sbt-noname, my-project sbt.plugins.JUnitXmlReportPlugin: enabled in multi-plugin, sbt-noname, my-project sbtnoname.Plugin: enabled in multi-plugin, sbt-noname, my-project > my-project/test:sayHello I'm the plugin to say hello [success] Total time: 0 s, completed Jun 15, 2014 3:49:50 PM 
+4
source

All Articles