Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT: Run an action on all projects

Tags:

scala

sbt

I have an SBT project that contains multiple subprojects, i.e.:

> projects
[info] In file:/home/me/src/foo/
[info]     popen
[info]     foobar-core
[info]   * foobar-client
[info]     foobar-db

Is there a way to run an action in each of these subprojects? I'm looking for something like publish-all, since I currently go through all the subprojects and run publish manually, which gets fairly tedious once there are more than a handful of subprojects.

I'm using sbt-0.11.2 out of inertia, but am willing to upgrade if that helps.

like image 648
themel Avatar asked Sep 05 '12 10:09

themel


People also ask

How do I run a sbt task?

Run “sbt hello” from command line to invoke the task. Run “sbt tasks” to see this task listed.

What is ThisBuild in sbt?

Typically, if a key has no associated value in a more-specific scope, sbt will try to get a value from a more general scope, such as the ThisBuild scope. This feature allows you to set a value once in a more general scope, allowing multiple more-specific scopes to inherit the value.

Does sbt run compile?

sbt is a popular tool for compiling, running, and testing Scala projects of any size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies or more than one code file.

What is the difference between sbt and Scala?

If you call scala, you will get whatever scala version is installed on the path of your operating system. If you call sbt console, you get the scala version configured in the sbt build (build. sbt) with all libraries that are used in the build already on the classpath.


1 Answers

You can define a project that aggregates all the other projects. Each action run on this project will be run on all aggregates. Here is an example from the sbt wiki:

import sbt._
import Keys._

object HelloBuild extends Build {
    lazy val root = Project(id = "hello",
                            base = file(".")) aggregate(foo, bar)

    lazy val foo = Project(id = "hello-foo",
                           base = file("foo"))

    lazy val bar = Project(id = "hello-bar",
                           base = file("bar"))
}
like image 164
Kim Stebel Avatar answered Oct 04 '22 19:10

Kim Stebel