Search code examples
playframework-2.2

Using Play!Framework 2.2 subprojects


I'm trying to split my Play!Framework 2.2 project in subprojects and I have some hard time figuring it out.

Here's my folder structure :

MyProject/
 | - app/
 | --- controllers/ # containing some main controllers
 | --- views/ # resulting views
 | - build.sbt # see after
 | - conf/
 | --- application.conf
 | --- routes
 | --- modules/ # My modules folder, aka sub projects
 | -------- common/
 | ------------ app/
 | --------------- models/ # The models
 | --------------- utils/
 | -------- api/
 | -------- web/
 | ------------ app/ # some controllers/views
 | ------------ conf/ # routes mainly
 | ------------ app/ # some controllers/views
 | ------------ conf/ # routes mainly

(I simplified it).

The main routes file :

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                             controllers.StaticPages.index()

# Web
->  /html/v1 web.Routes

# API
->  /api/v1  api.Routes

web.routes :

# HTML Engine renderer
# ~~~~~~~~~~~~~~~~~~~~

GET   /users                controllers.Users.list()

api.routes :

# API
# ~~~~~~~~~~~~~~~~~~~~

GET   /users                controllers.Users.list()

And finally, my build.sbt

import play.Project._

name := "My project"

version := "1.0-alpha"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  "mysql" % "mysql-connector-java" % "5.1.25",
  "com.typesafe" %% "play-plugins-mailer" % "2.2.0"
)

play.Project.playJavaSettings

lazy val root = project.in(file("."))
    .dependsOn(common, web, api)
    .aggregate(common, web, api)

lazy val web = project.in(file("modules/web"))
    .dependsOn(common)

lazy val api = project.in(file("modules/api"))
    .dependsOn(common)

lazy val common = project.in(file("modules/common"))

When cleaning/compiling and running, I face this error :

not found: value web In /path/to/project/conf/routes at line 20. -> /html/v1 web.Routes

If I remove the -> in the main routes file, Play! cannot find the package utils in common.

So I guess common, web and api aren't loaded, but why?

Update

Since @James-roper helped me found the problem, I created a Github repository that shows a simple Play!Framework 2.2 project with sub projects. You can find it here : https://github.com/cnicodeme/play2.2-subproject


Solution

  • Your sub projects need to use different package names, at the moment they are conflicting.