Play sub-projects do not compile

回眸只為那壹抹淺笑 提交于 2020-01-14 18:51:50

问题


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?


回答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 ;-)



来源:https://stackoverflow.com/questions/20315461/play-sub-projects-do-not-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!