playframework - 使用 Play Framework 2.5 的多应用项目
问题描述
我想用 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
解决方案
我通过在主 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)
推荐阅读
- r - R - 面板数据 FE,没有唯一的时间 id 匹配,创建新的时间变量
- oracle - 为什么我在下面的代码中收到错误?
- docker - 无法连接到 Windows 上的 Docker 容器
- filter - 在组件内部运行的自定义过滤器和/或插件
- python - Python:将带有 Unicode 的字符串转换为 HTML 数字代码
- c# - 为什么 FindNextFile 在我的 C# 代码中不起作用?
- java - ANTLR4 从函数返回值
- php - 使用 PDO、MVC 和 PHP 将变量绑定到数据库查询的问题
- python - 如何使用 DataFrame 编辑 Excel 文件并将其另存为 Excel 文件?
- woocommerce - Wocomerce 导入带有自定义分隔符的 csv 文件产品