带有Play Framework 2.5的多应用项目

时间:2019-06-07 12:31:10

标签: playframework sbt

我想用Play Framework 2.5构建一个多应用程序项目,但我不明白为什么项目的一部分从未编译

这是项目的结构:

build.sbt (main sbt file)
common/ (common code shared by apps)
     build.sbt
     app/
     conf/
     public/
apps/
     app1/
         build.sbt
         app/
         conf/
         public/
     app2/
         build.sbt
         app/
         conf/
         public/
     ...

common/appX/是具有自己的build.sbt文件的Play Framework应用。

主要build.sbt文件:

lazy val common = (project in file("common"))

lazy val app1 = (project in file("apps/app1"))

lazy val app2 = (project in file("apps/app2"))

lazy val root = (project in file("."))
  .dependsOn(common, app1, app2)
  .aggregate(common, app1, app2)

常见的build.sbt文件:

import WebJs._
import RjsKeys._

scalaVersion := "2.11.11"

lazy val common = (project in file("."))
  .enablePlugins(PlayJava, PlayEbean, SbtWeb)

// Add dependencies from Maven
libraryDependencies ++= Seq(
  filters,
  javaCore,
  javaJdbc,
  cache,
  javaWs
)

// Enable JavaScript uglifying
pipelineStages := Seq(rjs, uglify, digest)

// Enable CSS optimization
buildProfile := JS.Object("optimizeCss" -> "standard")

// Disable strange behavior in local run
fork in run := false

// Configure the Eclipse project as a Java project
EclipseKeys.projectFlavor := EclipseProjectFlavor.Java
EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources)
EclipseKeys.preTasks := Seq(compile in Compile)

// Remove eviction warnings
evictionWarningOptions in update := EvictionWarningOptions.default.withWarnTransitiveEvictions(false)

app1 build.sbt文件:

name := """app1"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.11"

lazy val common = (project in file("../../common"))
lazy val app1 = (project in file("."))
  .enablePlugins(PlayJava)
  .dependsOn(common)

app2 build.sbt文件:

name := """app2"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.11"

lazy val common = (project in file("../../common"))
lazy val app2 = (project in file("."))
  .enablePlugins(PlayJava)
  .dependsOn(common)

通常,我具有通用源代码的路由(例如:用户控制器),并且每个应用程序都有一个路由文件。

当我尝试使用sbt compile进行编译时,我得到以下输出:

[info] Updating {file:/myProject/}root...
[info] Compiling 35 Scala sources and 44 Java sources to /myProject/apps/app1/target/scala-2.11/classes...
[info] Compiling 41 Scala sources and 47 Java sources to /myProject/apps/app2/target/scala-2.11/classes...
[info] Resolving common_2.10;0.1-SNAPSHOT ...
[warn]  module not found: common_2.10;0.1-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/.../common_2.10/0.1-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/common_2.10/0.1-SNAPSHOT/common_2.10-0.1-SNAPSHOT.pom
[info] Resolving app1_2.10;1.0-SNAPSHOT ...
[warn]  module not found: app1_2.10;1.0-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/.../app1_2.10/1.0-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/app1_2.10/1.0-SNAPSHOT/app1_2.10-1.0-SNAPSHOT.pom
[info] Resolving app2_2.10;1.0-SNAPSHOT ...
[warn]  module not found: app2_2.10;1.0-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/.../app2_2.10/1.0-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/app2_2.10/1.0-SNAPSHOT/vestacharger_2.10-1.0-SNAPSHOT.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: common_2.10;0.1-SNAPSHOT: not found
[warn]  :: app1_2.10;1.0-SNAPSHOT: not found
[warn]  :: app2_2.10;1.0-SNAPSHOT: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Unresolved dependencies path:
[warn]      common_2.10:0.1-SNAPSHOT
[warn]        +- root:root_2.10:0.1-SNAPSHOT
[warn]      app1_2.10:1.0-SNAPSHOT
[warn]        +- root:root_2.10:0.1-SNAPSHOT
[warn]      app2_2.10:1.0-SNAPSHOT
[warn]        +- root:root_2.10:0.1-SNAPSHOT
[error] /myProject/apps/app1/app/views/activity/activitiesTable.scala.html:1: not found: type User
[error] @******************************************************************************
[error] ^
...

我的结构部分基于以下项目:https://github.com/josh-padnick/play-multiproject-template和SBT文档:https://www.scala-sbt.org/1.x/docs/Multi-Project.html 通用应用程序根本无法编译。为什么?这是实现我目标的好方法吗?

谢谢。

编辑: 如果我做sbt; project common; compile,则什么也没发生:

[info] Updating {file:/myProject/}common...
[info] Resolving jline#jline;2.14.3 ...
[info] Done updating.
[success] Total time: 2 s, completed Jun 7, 2019 2:27:09 PM

1 个答案:

答案 0 :(得分:0)

我通过在主要sbt文件中移动enablePlugins来解决此问题:

lazy val common = (project in file("common"))
  .enablePlugins(PlayJava, PlayEbean, SbtWeb)

lazy val app1 = (project in file("apps/app1"))
  .enablePlugins(PlayJava)
  .dependsOn(common)

lazy val app2 = (project in file("apps/app2"))
  .enablePlugins(PlayJava)
  .dependsOn(common)

lazy val root = (project in file("."))
  .dependsOn(common, app1, app2)
  .aggregate(common, app1, app2)