How to create sub projects in Play Framework? (play#play-java_2.9.2;2.1-RC3: not found)
Asked Answered
E

2

8

I want to test how sub projects work, especially how the routes of the sub project are taken into account in main project (this was not visible before).

I have read the docs here: https://github.com/playframework/Play20/wiki/SBTSubProjects

What have I done: (after downloading play 2.1 RC3)

  1. Create new Java Project: play new MainProject
  2. Create new folder inside MainProject: modules
  3. Create new Java Project: play new SubProject

On both projects: play eclipse since play eclipsify does not work anymore

In the main projects Build.scala file:

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val appName         = "MainProject"
  val appVersion      = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,
    javaCore,
    javaJdbc,
    javaEbean 
  )

  val subProject = Project("subproject", file("modules/SubProject"))

  val main = play.Project(appName, appVersion, appDependencies).settings(
    // Add your own project settings here      
  ).dependsOn(subProject)

}

Now, in the main project I run:

play run

And I get the following errors:

[error] (MainProject/*:update) sbt.ResolveException: unresolved dependency: play#play_2.9.2;2.1-RC3: not found
[error] unresolved dependency: play#play-java_2.9.2;2.1-RC3: not found
[error] unresolved dependency: play#play-java-jdbc_2.9.2;2.1-RC3: not found
[error] unresolved dependency: play#play-java-ebean_2.9.2;2.1-RC3: not found
[error] unresolved dependency: play#play-test_2.9.2;2.1-RC3: not found

Note I have tried to delete the Build.scala from the subproject but I kep getting this error.

What am I doing wrong?

Eatage answered 29/1, 2013 at 15:53 Comment(2)
Can you write the structure of your project? I have done exactly same as described in the link SBTSunProjects. But I'm getting the above listed errors.Coelostat
This weekend I will try to do that, both for Scala and Java.Eatage
E
12

Finally got it working:

  • You do not have to delete the Build.scala from the subproject.

You need to rename the routes file of your sub project. In my example, to subProject.routes. If you want to run your subproject in isolation you need to declare that routes must resolve to your subProject.routes. So add this in the application.conf of your subProject:

application.router=subProject.Routes

In your main project, you need to import the routes from the subproject:

->  /subProject               subProject.Routes

And the build file of the main project should look something like: example is from SCALA but s

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val appName         = "MainProject"
  val appVersion      = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,
   javaCore,
   javaJdbc,
   javaEbean 
  )

  val subProject = play.Project(
    appName + "-subProject", appVersion, path = file("modules/SubProject")
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(
    // Add your own project settings here      
  ).dependsOn(subProject)

}
Eatage answered 31/1, 2013 at 16:7 Comment(2)
Thanks adis! In my case it doesn't find the subProject "package" in subProject.Routes (in routes file). I don't know what have I done wrong.Appraisal
@FerranMaylinch Sounds like something I had when my controllers weren't declared within 'controllers.' namespace. Seems they have to be.Dream
A
0

I found that I had to explicitly set the scala version to 2.10.0 because the subprojects caused a conflict with 2.9.2.

val main = play.Project(appName, appVersion, appDependencies).settings(
    scalaVersion := "2.10.0"
)

Example taken from this question.

Appraisal answered 28/5, 2015 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.