播放子项目无法编译 [英] Play sub-projects do not compile

查看:103
本文介绍了播放子项目无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的多项目Play 2.2应用程序的布局-我仍在尝试转换为build.sbt:

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:

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:

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:

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)即使仅子项目具有依赖项(主项目只是许多子项目的容器),我也必须在主构建文件myApp/build.sbt中指定resolvers;如果我不这样做,该项目将无法编译.这不是一个阻塞性问题.但是我想了解原因.

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)然后,一旦我尝试编译项目,我总是会收到以下错误:

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

这是myApp/conf/routes ...

Here is 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:

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

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

我想念什么吗?

推荐答案

弄清楚如何使其工作,下面是我的解决方案.首先,我为所有项目[myApp/project/Build.scala]定义了默认设置和解析器:

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
  ) 
}

然后我刚刚将ApplicationBuild.defaultSettings导入到每个build.sbt中.这是主要的项目构建文件[myApp/build.sbt] ...

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

...以及此处的子项目构建文件[myApp/modules/myModule/build.sbt]:

... 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 ;-)

这篇关于播放子项目无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆