SBT subprojects do not recognize plugin commands

I am having trouble getting SBT Subprojects to recognize the commands provided by the plugins. I have the following plugin source:

object DemoPlugin extends AutoPlugin { override lazy val projectSettings = Seq(commands += demoCommand) lazy val demoCommand = Command.command("demo") { (state: State) => println("Demo Plugin!") state } } 

which is used by a project configured as follows:

 lazy val root = project in file(".") lazy val sub = (project in file("sub")). enablePlugins(DemoPlugin). settings( //... ) 

The plugin, of course, is specified in project/plugins.sbt . However, when I open sbt in the project, I see the following:

 > sub/commands [info] List( sbt.SimpleCommand@413d2cd1 ) > sub/demo [error] Expected ':' (if selecting a configuration) [error] Not a valid key: demo (similar: doc) [error] sub/demo 

Even a stranger, using consoleProject , I see that the command in the project is the one defined by DemoPlugin !

 scala> (commands in sub).eval.map { c => c.getClass.getMethod("name").invoke(c) } res0: Seq[Object] = List(demo) 

I am looking to be able to type sub/demo and execute the demo command. Any help would be greatly appreciated!

+6
source share
1 answer

Teams are not intended for each project. They work only for a top-level project.

It is also recommended that you try and use tasks or, if necessary, input tasks, where you can use the command.

If you really need a team, there is a way to have a kind of β€œholder” task, see the answer for Can you access the SBT SettingKey inside the team?

+1
source

Source: https://habr.com/ru/post/982803/


All Articles