Run "clear" all dependent SBT subprojects

I have an SBT project, in particular a Play Framework 2.1 project, which has several subprojects specified in the configuration. Dependencies seem to work fine while compiling, but "clean" only seems to clear the selected project, not including its dependencies. Is there a way to clear the selected project and its dependent subprojects?

+6
source share
1 answer

If your main project combines objects, for example:

lazy val root = Project("name", file(".")) .aggregate(module1, module2, macros) 

then any command invoked by this root project will be executed for all subprojects. If you call the inspect clean command in your sbt session, you will see in the Related section all the subprojects that are related to this clean

Side notes in comments

aggregate and dependsOn are different commands for different purposes. The purpose of aggregation is to execute commands invoked in the root project. In my example, by invoking the test command in my root project, this command will also be executed for module1 module2 and macros . If you want to disable this behavior with the following setting:

 aggregate in test := false 

An aggregated project is independent of the code in them. It is usually used in a root project, for example, not to call test for each project, but to call it root. Remember that in the case of aggregation commands will be executed in parallel.

And dependsOn means that your project will depend on code from another project. And in this case, SBT will execute the sequentialy command to compile your root project, which dependsOn some modules, it must compile these modules in the first step, the root project.

+6
source

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


All Articles