Mnemosyne Mnemosyne - 3 months ago 14
Scala Question

Routing does not recognize modules for my sbt-multimodule project in Play 2 (code and error mesage inside)

I am writing a modular application using Play 2 and decided to create sbt components as modules for the bigger framework. The application structure looks like this:

project
- build.sbt
- app
- controllers
- models
- bin
- conf
- application.conf
- routes
- modules
- index
- app
- controllers
- models
- conf
- index.routes
- project
- build.sbt
- register
- app
- controllers
- models
- conf
- register.routes
- project
- build.sbt


The configuration of
build.sbt
is:

name := """project"""

version := "1.0-SNAPSHOT"


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

lazy val root = (project in file(".")).enablePlugins(PlayScala)
.dependsOn(index,register).aggregate(index,register)

scalaVersion := "2.11.8"

libraryDependencies ++= Seq(
jdbc,
cache,
ws,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"


This is how
conf/routes
looks like

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



# Homepage
GET / controllers.HomeController.homepage

#Application
-> /index index.Routes
# currently I'm only trying to get the first module to work


And this is my
index.routes


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

# An example controller showing a sample home page

GET / controllers.index.Application.list()


However everytime I try any http request I get essentially

[error] /home/.../project/conf/routes:12: not found: value index
[error] -> /index index.Routes
[error] /home/.../project/conf/routes:12: not found: value index
[error] -> /index index.Routes
[error] /home/.../project/conf/routes:12: not found: value index
[error] -> /index index.Routes
[error] three errors found
[error] (root/compile:compileIncremental) Compilation failed
[error] application -

! @715gad4do - Internal server error, for (GET) [/] ->

play.sbt.PlayExceptions$CompilationException: Compilation error[not found: value index]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
at scala.Option.map(Option.scala:145)
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49)
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
at scala.Option.map(Option.scala:145)
at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44)
at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40)
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)


I have tried to find the correct routing method but from everything I've researched all day this is the correct method to access sbt submodules through the primary Play App but for some reason it doesnt work for me. What could be wrong with my configuration?

Answer

For anyone who ever encounters a similar problem: the trick is to write at the top of the 'module.routes` file (module being the name of whatever submodule you have) :

# MODULE Routes