/ / Play-Unterprojekte werden nicht kompiliert - scala, playframework, sbt

Play Sub-Projekte nicht kompilieren - scala, playframework, sbt

Hier ist das Layout meiner Play-2.2-Anwendung für mehrere Projekte - ich versuche immer noch, in build.sbt zu konvertieren:

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
)

Ich habe zwei Probleme, wenn ich das obige Projekt kompilieren möchte:

1) Auch wenn nur das Unterprojekt Abhängigkeiten hat (das Hauptprojekt ist nur ein Container für viele Unterprojekte), muss ich das angeben resolvers auch in der Hauptdatei myApp/build.sbt; Wenn ich das nicht mache, wird das Projekt nicht kompiliert. Dies ist kein Blockierungsproblem .. aber ich möchte verstehen, warum.

2) Sobald ich versuche, das Projekt zu kompilieren, erhalte ich immer die folgende Fehlermeldung:

[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

Hier ist meinApp / Conf / Routen ...

GET     /                           controllers.Application.index

-> /myModule myModule.Routes

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

... und zum Schluss noch myApp / modules / myModule / conf / myModule.routes:

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

Fehle ich etwas?

Antworten:

1 für die Antwort № 1

Ich habe herausgefunden, wie es funktioniert und hier ist meine Lösung. Zunächst einmal habe ich Standardeinstellungen und Resolver für alle Projekte definiert [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
)
}

Dann habe ich gerade importiert ApplicationBuild.defaultSettings in jeden build.sbt. Hier ist die Hauptprojektdatei [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

... und hier die Unterprojekt-Builddatei [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"
)

Es funktioniert einfach und ich hoffe es hilft ;-)