5

sbt allows us to run sbt commands on the root project level.

How can I run commands on the meta-build level? (that is defined in root/project/project dir)

my use case is that some of my sbt plugins have different versions of the same dependency, and the older dependencies are evicted. I would like to investigate using sbt-dependency-graph

lev
  • 3,986
  • 4
  • 33
  • 46

3 Answers3

8

You can use reload plugins from the main project sbt session to switch into context of the build project:

sbt:root> reload plugins
[snip noise]

sbt:project> show libraryDependencies
[shows your sbt plugins from root/plugins.sbt along with their deps]

sbt:project> reload return
[back to the main project]

sbt:root>

As Jorge noted, you can install sbt-dependency-graph in the meta-build of root/project/project/plugins.sbt to make it available to the build project context of reload plugins. As always, recall that sbt is recursive—from the build project you can do reload plugins again to reach the meta-build level. From there show libraryDependencies would show only sbt-dependency-graph from root/project/project, for example.

This is a quirky aspect of sbt UX in my opinion, because it's not exactly intuitive that the reload command would be the path to this feature, but as long as you can remember that part, help reload gives a good summary for recalling the subcommands.

I don't know if this is the "wrong" way in any regard, but I find it more convenient than changing directories since I don't need to start another sbt session, and can move back and forth or recurse further without restarting.

ches
  • 6,382
  • 2
  • 35
  • 32
2

The right way to do this is to run sbt in root/project. You usually just run it on root/, the trick is to cd into project and run it there. If you want to check the library dependencies resolved in the meta build, you can add the sbt dependency graph plugin in root/project/project/plugins.sbt (note the repetition of project), and then you should be able to run dependencyBrowseGraph from the sbt shell.

Jorge
  • 784
  • 4
  • 17
0

as a workaround, I did the following thing:

in the file root/project/plugins.sbt :

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")

and in the file root/project/build.sbt:

(compile in Compile) := {
  (dependencyBrowseGraph in Compile).value
  (compile in Compile).value
}

this causes the dependencyBrowseGraph task to run after the compile. it's solve my specific problem, but it's not very convenient, so it would be nice to hear what is the right way to do it.

lev
  • 3,986
  • 4
  • 33
  • 46