3

Here is the layout of my multi-project Play 2.2 application - I'm still trying to convert to build.sbt:

myApp
  + app
  + build.sbt
  + conf
  |   + routes
  + project
  |  + build.properties
  |  + Build.scala
  |  + plugin.sbt
  + modules
     + myModule
         + app
         + build.sbt
         + conf
             + routes

myApp/build.sbt:

name := "myApp"

version := "1.0-SNAPSHOT"

organization := "com.mydomain"

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

lazy val main = project.in(file(".")).dependsOn(myModule).aggregate(myModule)

play.Project.playScalaSettings

resolvers ++= Seq(
  Resolvers.typesafe,
  Resolvers.sonatype
)

myApp/projects/Build.scala:

import sbt._

object Resolvers {
  val sonatype = Resolver.sonatypeRepo("snapshots")
  val typesafe = "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
}

myApp/modules/myModule/build.sbt:

name := "myModule"

libraryDependencies ++= Seq(
  "com.typesafe.play" %% "play" % "2.2.1" % "provided",
  "org.reactivemongo" %% "reactivemongo" % "0.10.0-SNAPSHOT",
  "org.reactivemongo" %% "play2-reactivemongo" % "0.10.0-SNAPSHOT"
)

resolvers ++= Seq(
  Resolvers.typesafe,
  Resolvers.sonatype
)

I'm facing with two problems when trying to compile the project above:

1) Even if only the sub-project has dependencies (the main project is just a container for many sub-projects), I have to specify the resolvers also in the main build file myApp/build.sbt; if I don't, the project doesn't compile. This is not a blocking problem.. but I'd like to understand why.

2) Then, as soon as I try to compile the project, I always get the following error:

[error] /home/j3d/Projects/myApp/conf/routes:9: not found: value myModule
[error] -> /myModule myModule.Routes
[error] /home/j3d/Projects/myApp/conf/routes: not found: value myModule
[error] /home/j3d/Projects/myApp/conf/routes:12: not found: value myModule
[error] GET     /assets/*file               controllers.Assets.at(path="/public", file)
[error] /home/j3d/Projects/myApp/conf/routes:9: not found: value handler
[error] -> /myModule myModule.Routes
[error] four errors found
[error] (main/compile:compile) Compilation failed
[error] Total time: 12 s, completed Dec 1, 2013 6:34:55 PM

Here is myApp/conf/routes...

GET     /                           controllers.Application.index

-> /myModule myModule.Routes

GET     /assets/*file               controllers.Assets.at(path="/public", file)

... and finally here is myApp/modules/myModule/conf/myModule.routes:

GET     /myModule/greetings         controllers.myModule.Greetings.hello

Am I missing something?

j3d
  • 9,492
  • 22
  • 88
  • 172

1 Answers1

1

Figured out how to make it work and here below is my solution. First of all I've defined default settings and resolvers for all projects [myApp/project/Build.scala]:

import sbt._
import Keys._

object ApplicationBuild extends Build {

  val defaultResolvers = Seq(
    Resolver.sonatypeRepo("snapshots"),
    "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
  )

  val defaultSettings = Defaults.defaultSettings ++ Seq(
    scalacOptions += "-language:reflectiveCalls",
    resolvers ++= defaultResolvers
  ) 
}

Then I've just imported ApplicationBuild.defaultSettings into every build.sbt. Here is the main project build file [myApp/build.sbt]...

name := "myApp"

version := "1.0-SNAPSHOT"

lazy val auth = project.in(file("modules/myModule"))

lazy val main = project.in(file(".")).dependsOn(myModule).aggregate(myModule)

ApplicationBuild.defaultSettings

playScalaSettings

... and here the sub-project build file [myApp/modules/myModule/build.sbt]:

name := "myModule"

ApplicationBuild.defaultSettings

playScalaSettings

libraryDependencies ++= Seq(
  "org.reactivemongo" %% "play2-reactivemongo" % "0.10.0-SNAPSHOT",
  "org.reactivemongo" %% "reactivemongo" % "0.10.0-SNAPSHOT"
)

It just works and hope it helps ;-)

j3d
  • 9,492
  • 22
  • 88
  • 172
  • A few years have gone since this solution which is still causing an issue (at least for me). In Play 2.6 `defaultSettings` is deprecated so `coreDefaultSettings` is used instead however the extended class/trait `Build` is also deprecated and I can't find what to use instead. IntelliJ is suggesting that I use `.sbt format` but I'm not sure in what syntax. Any ideas? – jesus g_force Harris Oct 25 '17 at 17:51