1

I've been working with these docs: https://www.playframework.com/documentation/2.4.x/SBTSubProjects and have split up a large project in a main and a sub module.

Some 7000 compiler errors, lots of caffeine and a whole to of "wow -- wish I knew that before"'s later I have the project working once more with it's new modular layout.

Now I want to create a second sub-module.

Let's call the main module ROOT and we'll can sub-module A ModA and sub-module B ModB.

ROOT will depend upon ModA and ModB

ModA will not depending on anything

ModB will depend upon ModA

Will it be more elegant (read: maintainable) to have ModA and ModB be siblings or is it mode elegant to have a chain of submodules indicating the flow of inheritance?

ROOT -> ModB -> ModA

This will get mess(ier) if (when) we add ModC and ModD etc so I'm hoping we can do this with the sibling's model.

Most of the magic appears here I believe:

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val ROOT = (project in file("."))
    .enablePlugins(PlayScala).dependsOn(ModA).aggregate(ModA)

I'll presume that I can chain the dependsOn and aggregate calls.

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val moduleB = (project in file("modules/ModB")).enablePlugins(PlayScala)

    lazy val ROOT = (project in file("."))
.enablePlugins(PlayScala).dependsOn(ModA)
.aggregate(ModA).dependsOn(ModB).aggregate(ModB)

Using the siblings model how would the dependancy of ModB to ModA be declared? (assuming in build.sbt of ModB)

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val ROOT = (project in file("."))
    .enablePlugins(PlayScala).dependsOn(ModA).aggregate(ModA)
Techmag
  • 1,383
  • 13
  • 24

1 Answers1

1

This should work just fine :

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val moduleB = (project in file("modules/ModB")).enablePlugins(PlayScala).dependsOn(moduleB)

    lazy val ROOT = (project in file("."))
.enablePlugins(PlayScala).dependsOn(moduleB)

It will transitively depend on mod A. Also notice that dependsOn and aggregate should reference the lazy val's name, not the folder name.

I don't think you actually need the aggregate in this case since you have dependencies. here is a more complex example with both aggregate and multiple dependencies:

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val moduleC = (project in file("modules/ModC")).enablePlugins(PlayScala)

lazy val moduleB = (project in file("modules/ModB")).enablePlugins(PlayScala).dependsOn(moduleB)

lazy val myapp = (project in file("myapp")).enablePlugins(PlayScala).dependsOn(moduleB, moduleC)

lazy val batch = (project in file("batch")).enablePlugins(PlayScala).dependsOn(moduleB)

lazy val ROOT = (project in file("."))
.aggregate(myapp, batch)

This way the toplevel (root) doesn't actually have code and doesn't depend on anyone, it simply aggregates you webapp and it's companion batch which both depend on ModB which itself depends on ModA

Jean
  • 21,329
  • 5
  • 46
  • 64