2

quite new with Play framework, but I tried to setup subproject for my main project but when I tried to redirect the route from the main project to subproject, it couldnt recognise the subproject variable. I have followed based on the documentation here PlaySubProject

My main project structure is as illustrated below:

Main
   app
   conf
      application.conf
      routes
   modules
      sub
         app
         conf
            sub.routes
         build.sbt
   logs
   project
   public
   target
   test
   activator
   activator-launch-1.2.10.jar
   build.sbt

This is my main build.sbt file:

name := """Main"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava).aggregate(sub).dependsOn(sub)

lazy val sub = (project in file("modules/sub")).enablePlugins(PlayJava)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs
)

and my subproject build.sbt is as follows:

name := """Subproject"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs
)

Finally, this is my main routes file.

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

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

# Map static resources from the /public folder to the /assets URL path
GET        /assets/*file        controllers.Assets.at(path="/public", file)

# SUB's
->  /sub    sub.Routes

The problem is in this routes file, it cannot even recognize sub variable on the last line at sub.Routes. How to solve this problem?

Cipher Hat
  • 23
  • 3

2 Answers2

1

I've had the same issue (although project structure was as in all examples and documenctations and routes files were in the right places) - sub-projects routes file haven't been placed into the main target/scala-2.11/routes and couldn't be find

I solved it by adding unmanagedResourceDirectories in Compile += baseDirectory.value / "<path_to_project>/conf at the end of build.sbt:

....
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .aggregate(core, providers, zms, api)
  .dependsOn(core, providers, zms, api)

lazy val core = (project in file("apps/core")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .settings(
    name := "core"
  )

lazy val zms = (project in file("apps/zms")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .settings(
    name := "zms"
  )
  .dependsOn(core)

lazy val api = (project in file("apps/api")).enablePlugins(PlayJava, PlayEbean)
  .settings(commonSettings: _*)
  .settings(
    name := "api"
  )
  .dependsOn(core)


//Here are the lines that solved the problem
unmanagedResourceDirectories in Compile += baseDirectory.value / "apps/core/conf"
unmanagedResourceDirectories in Compile += baseDirectory.value / "apps/zms/conf"
unmanagedResourceDirectories in Compile += baseDirectory.value / "apps/api/conf"

fork in Compile := true

It will say sbt to add files under sub-project conf directory to be included in the main project classpath

lub0v
  • 801
  • 9
  • 17
0

I'm not sure about your specific issue, but I setup a fully working and reasonably well-documented multi-project example at https://github.com/josh-padnick/play-multiproject-template. This is based on Play 2.2.3 (not 2.3.x), but it should be pretty close to what you need.

Josh Padnick
  • 3,157
  • 1
  • 25
  • 33
  • well, this is really silly. I figured my problem was not with the Play Framework, but confusion with Intellij IDEA's red highlighting on sub.Routes. With your template, I figured this was the case. I run the project and it works just fine. I just have to ignore the red text highlighted by IntelliJ on that part. Thanks btw. – Cipher Hat Oct 05 '14 at 02:15