Sample directory structure and file-contents for a one-module, one-app play
build. It illustrates how routes compilation and resolution might work in a way that
avoids namespace collision on the controllers.routes
symbol (a bug in Play 2.0.x).
The initial version of this gist demonstrates the behavior of the pull request that solves that bug, authored by @jroper:
Though this solves a pretty huge problem in our company, the reverse router
syntax is a bit unsatisfying due to the awkward syntax of module reverse routes:
controllers.module.module.routes.Module
Can that be improved without introducing more opportunity for namespace collision?
application/
app/controllers/Application.scala
| // Controllers for the application
| package controllers
|
| object Application {
|
| def index = Ok("Welcome to the application")
|
| // v-- module.module.routes.Module is unsatisfying
| def moduleIndex = Redirect(controllers.module.module.routes.Module.index)
| }
conf/routes
| # Application routes
| GET / controllers.Application.index
|
| -> /module module.Routes
module/
app/controllers/module/Module.scala
| // Controllers for the module, responsibly namespaced so that they
| // can be good citizen when included in other projects.
| package controllers.module
|
| object Module {
| def index = Ok("Welcome to the Module")
| }
conf/module.routes
| # routes for the module. Excluding an Assets route
| # to keep the example simple. Maybe I should include it?
|
| GET / controllers.module.Module.index
Upon routes compilation, this project layout produces two routes.java
files:
module/target/scala-2.10/src_managed/main/controllers/module/module/routes.java
| // Generated by module/conf/module.routes. The path unsatisfyingly resolves
| // to module/module because conf/module.routes contained a reference to
| // controllers.module.Module.
| //
| // It is this location that requires app/controllers/Application.scala to reference
| // the reverse router as controllers.module.module.routes.
| //
| // Can we fix that without introducing further namespace collisions?
|
| package module.module
|
| public class routes { /* impl */ }
application/target/scala-2.10/src_managed/main/controllers/routes.java
| // Generated by application/conf/routes
| package controllers
| public class routes { /* impl */ }