Multi-app project with Play Framework 2.5

Hi,

I’d like to build a multi-app project with Play Framework 2.5 but I don’t understand why a part of the project never compiles

Here is the structure of the project:

build.sbt (main sbt file)
common/ (common code shared by apps)
     build.sbt
     app/
     conf/
     public/
apps/
     app1/
         build.sbt
         app/
         conf/
         public/
     app2/
         build.sbt
         app/
         conf/
         public/
     ...

common/ and appX/ are Play Framework apps with their own build.sbt file.

main build.sbt file:

lazy val common = (project in file("common"))

lazy val app1 = (project in file("apps/app1"))

lazy val app2 = (project in file("apps/app2"))

lazy val root = (project in file("."))
  .dependsOn(common, app1, app2)
  .aggregate(common, app1, app2)

common build.sbt file:

import WebJs._
import RjsKeys._

scalaVersion := "2.11.11"

lazy val common = (project in file("."))
  .enablePlugins(PlayJava, PlayEbean, SbtWeb)

// Add dependencies from Maven
libraryDependencies ++= Seq(
  filters,
  javaCore,
  javaJdbc,
  cache,
  javaWs
)

// Enable JavaScript uglifying
pipelineStages := Seq(rjs, uglify, digest)

// Enable CSS optimization
buildProfile := JS.Object("optimizeCss" -> "standard")

// Disable strange behavior in local run
fork in run := false

// Configure the Eclipse project as a Java project
EclipseKeys.projectFlavor := EclipseProjectFlavor.Java
EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources)
EclipseKeys.preTasks := Seq(compile in Compile)

// Remove eviction warnings
evictionWarningOptions in update := EvictionWarningOptions.default.withWarnTransitiveEvictions(false)

app1 build.sbt file:

name := """app1"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.11"

lazy val common = (project in file("../../common"))
lazy val app1 = (project in file("."))
  .enablePlugins(PlayJava)
  .dependsOn(common)

app2 build.sbt file:

name := """app2"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.11"

lazy val common = (project in file("../../common"))
lazy val app2 = (project in file("."))
  .enablePlugins(PlayJava)
  .dependsOn(common)

etc.

in common I have the routes for the common source code (ex: User controller) and I also have a route file for each app.

When I try to compile with sbt compile, I have this output:

[info] Updating {file:/myProject/}root...
[info] Compiling 35 Scala sources and 44 Java sources to /myProject/apps/app1/target/scala-2.11/classes...
[info] Compiling 41 Scala sources and 47 Java sources to /myProject/apps/app2/target/scala-2.11/classes...
[info] Resolving common_2.10;0.1-SNAPSHOT ...
[warn] 	module not found: common_2.10;0.1-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/.../common_2.10/0.1-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/common_2.10/0.1-SNAPSHOT/common_2.10-0.1-SNAPSHOT.pom
[info] Resolving app1_2.10;1.0-SNAPSHOT ...
[warn] 	module not found: app1_2.10;1.0-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/.../app1_2.10/1.0-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/app1_2.10/1.0-SNAPSHOT/app1_2.10-1.0-SNAPSHOT.pom
[info] Resolving app2_2.10;1.0-SNAPSHOT ...
[warn] 	module not found: app2_2.10;1.0-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/.../app2_2.10/1.0-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/app2_2.10/1.0-SNAPSHOT/vestacharger_2.10-1.0-SNAPSHOT.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	::          UNRESOLVED DEPENDENCIES         ::
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	:: common_2.10;0.1-SNAPSHOT: not found
[warn] 	:: app1_2.10;1.0-SNAPSHOT: not found
[warn] 	:: app2_2.10;1.0-SNAPSHOT: not found
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn] 	Note: Unresolved dependencies path:
[warn] 		common_2.10:0.1-SNAPSHOT
[warn] 		  +- root:root_2.10:0.1-SNAPSHOT
[warn] 		app1_2.10:1.0-SNAPSHOT
[warn] 		  +- root:root_2.10:0.1-SNAPSHOT
[warn] 		app2_2.10:1.0-SNAPSHOT
[warn] 		  +- root:root_2.10:0.1-SNAPSHOT
[error] /myProject/apps/app1/app/views/activity/activitiesTable.scala.html:1: not found: type User
[error] @******************************************************************************
[error] ^
...

I’ve based my structure partially on this project: https://github.com/josh-padnick/play-multiproject-template and the SBT doc: https://www.scala-sbt.org/1.x/docs/Multi-Project.html
The common app doesn’t compile at all. Why? Is it the good way to proceed for my purpose?

Thanks.

Edit:
If I do sbt; project common; compile, nothing happen:

[info] Updating {file:/myProject/}common...
[info] Resolving jline#jline;2.14.3 ...
[info] Done updating.
[success] Total time: 2 s, completed Jun 7, 2019 2:27:09 PM

I fixed it by moving the enablePlugins in the main sbt file:

lazy val common = (project in file("common"))
  .enablePlugins(PlayJava, PlayEbean, SbtWeb)

lazy val app1 = (project in file("apps/app1"))
  .enablePlugins(PlayJava, PlayEbean, SbtWeb, DockerPlugin)
  .dependsOn(common)

lazy val app2 = (project in file("apps/app2"))
  .enablePlugins(PlayJava, PlayEbean, SbtWeb, DockerPlugin)
  .dependsOn(common)

lazy val root = (project in file("."))
  .dependsOn(common, app1, app2)
  .aggregate(common, app1, app2)
1 Like