播放子项目不编译

时间:2013-12-01 18:10:03

标签: scala playframework sbt

这是我的多项目Play 2.2应用程序的布局 - 我仍在尝试转换为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 /项目/ Build.scala:

import sbt._

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

对myApp /模块/ 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
)

我在尝试编译上面的项目时面临两个问题:

1)即使只有子项目有依赖项(主项目只是许多子项目的容器),我也必须在主构建文件resolvers中指定myApp/build.sbt ;如果我不这样做,该项目不会编译。这不是阻塞问题..但我想了解原因。

2)然后,一旦我尝试编译项目,我总是会收到以下错误:

[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

这是myApp / conf / routes ...

GET     /                           controllers.Application.index

-> /myModule myModule.Routes

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

...最后这里是myApp / modules / myModule / conf / myModule.routes:

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

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

想出如何使它工作,下面是我的解决方案。首先,我为所有项目[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
  ) 
}

然后我刚刚将ApplicationBuild.defaultSettings导入每个build.sbt。这是主项目构建文件[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

...这里是子项目构建文件[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"
)

它只是有效并希望它有所帮助; - )