Search code examples
scalaplayframeworkroutesmulti-project

Multi project routing does not work on playframework


Hi I'm trying to set up a multiproject scala playframework project, and I seem to have issues figuring what the issue is with my routing. SBT keeps on giving me cryptic errors. Has anyone else run into this error. What am I doing wrong here? Thanks!

build.sbt:

name := """server"""

libraryDependencies ++= {
  Seq(
    guice,
    "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test
  )
}

lazy val static = (project in file("modules/static")).enablePlugins(PlayScala)

lazy val main = (project in file(".")).enablePlugins(PlayScala).dependsOn(static).aggregate(static)

conf/routes:

-> /static static.Routes

modules/static/conf/static.routes

GET     /static/index                           controllers.Assets.at(path="/public", file="index.html")
GET     /static/assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

The error it gives me:

\server\modules\static\conf\static.routes: identifier expected but `.' found.

And another error that is given if its been compiled and then modified to the routes above:

play.sbt.PlayExceptions$CompilationException: Compilation error[identifier expected but `.' found.]
        at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:34)
        at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:34)
        at scala.Option.map(Option.scala:146)
        at play.sbt.run.PlayReload$.$anonfun$taskFailureHandler$1(PlayReload.scala:33)
        at scala.Option.map(Option.scala:146)
        at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:28)
        at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:24)
        at play.sbt.run.PlayReload$.$anonfun$compile$3(PlayReload.scala:51)
        at scala.util.Either$LeftProjection.map(Either.scala:573)
        at play.sbt.run.PlayReload$.compile(PlayReload.scala:51)

Solution

  • I checked with my project (Play 2.6):

    conf/routes:

    -> / static.Routes // at the end of the routing script

    modules/static/conf/static.routes:

    GET /static/index controllers.Default.redirect(to = "/static/index/") GET /static/index/ controllers.Assets.at(path="/public", file="index.html")

    If I remember correctly - the missing slash was the problem.