Play Framework [2.4.x] Work with additional modules

I worked with these documents: https://www.playframework.com/documentation/2.4.x/SBTSubProjects and shared a large project in the main and additional module.

Some 7000 compiler errors, a lot of caffeine and the whole β€œwow - I want me to know this before” project later with a new modular layout.

Now I want to create a second submodule.

Let us call the main module ROOT, and we can submodule A ModA and submodule B ModB.

ROOT will depend on ModA and ModB

ModA will not depend on anything

ModB will depend on ModA

Would it be more elegant (read: maintenanceable) for ModA and ModB to be siblings, or would it be elegant to have a chain of submodules indicating the flow of inheritance?

ROOT β†’ ModB β†’ ModA

It will be a mess (ier) if (when) we add ModC and ModD, etc., so I hope that we can do this using the sibling 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 assume that I can bind the calls to dependsOn and aggregate .

 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 will the dependence of ModB on ModA be announced? (assuming in build.sbt ModB)

 lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala) lazy val ROOT = (project in file(".")) .enablePlugins(PlayScala).dependsOn(ModA).aggregate(ModA) 
+1
source share
1 answer

This should work 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 be transitively dependent on mod A. Also note that dependOn and aggregate must refer to the lazy name val, not the folder name.

I do not think that you really need the amount in this case, since you have dependencies. here is a more complex example with 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) 

Thus, toplevel (root) actually has no code and is not dependent on anyone, it just integrates you into a webapp and its companion party, which depend on ModB, which itself depends on ModA

+1
source

All Articles