Play 子项目无法在 IntelliJ 上导入 Play-json 类
Play subproject can't import Play-json classes on IntelliJ
但是,为了更好地组织,我已将我的应用拆分为多个子项目。我的核心子模块是一个播放应用程序,无法导入 play.api.libs.json.Json
这是我的 build.sbt
# project/Common.scala
import sbt._
import sbt.Keys._
object Common {
val settings = Seq(
organization := "com.company.app",
scalaVersion := "2.12.5"
)
val dependencies = new {
val macwireVersion = "2.3.0"
val reactiveMongoVersion = "0.13.0-play26"
val slickVersion = "3.0.3"
val postgresVersion = "42.2.2"
val scalatestPlayVersion = "3.1.2"
val macwire = "com.softwaremill.macwire" %% "macros" % macwireVersion % "provided"
val reactivemongo = "org.reactivemongo" %% "play2-reactivemongo" % reactiveMongoVersion
val slick = "com.typesafe.play" %% "play-slick" % slickVersion
val slickEvolutions = "com.typesafe.play" %% "play-slick-evolutions" % slickVersion
val postgresql = "org.postgresql" % "postgresql" % postgresVersion
val scalatestPlay = "org.scalatestplus.play" %% "scalatestplus-play" % scalatestPlayVersion % Test
}
lazy val commonDependencies = Seq(
dependencies.macwire,
dependencies.reactivemongo,
dependencies.slick,
dependencies.slickEvolutions,
dependencies.postgresql,
dependencies.scalatestPlay
)
}
# build.sbt
lazy val core = (project in file("modules/core"))
.enablePlugins(PlayScala)
.settings(
name := "app-core",
libraryDependencies ++= Common.commonDependencies ++ Seq(
),
Common.settings
)
lazy val cms = (project in file("modules/cms"))
.enablePlugins(PlayScala)
.settings(
name := "app-cms",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val api = (project in file("modules/api"))
.enablePlugins(PlayScala)
.settings(
name := "app-api",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val reporting = (project in file("modules/reporting"))
.enablePlugins(PlayScala)
.settings(
name := "app-reporting",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val backend = (project in file("."))
.enablePlugins(PlayScala)
.settings(
name := "app-backend",
libraryDependencies ++= Common.commonDependencies
)
.dependsOn(
core % "test->test;compile->compile",
cms,
api,
reporting
)
.aggregate(cms, api, reporting)
我无法在核心模块中为我的模型用户添加隐式 Json 格式。
对于后端应用程序,我可以导入 w/o 问题,我在子模块部分缺少什么吗?
谢谢,
仔细检查您是否真的导入了 play-json
库,因为在 Play 2.6 中它是一个独立的库:
libraryDependencies += "com.typesafe.play" %% "play-json" % playVersion
但是,为了更好地组织,我已将我的应用拆分为多个子项目。我的核心子模块是一个播放应用程序,无法导入 play.api.libs.json.Json
这是我的 build.sbt
# project/Common.scala
import sbt._
import sbt.Keys._
object Common {
val settings = Seq(
organization := "com.company.app",
scalaVersion := "2.12.5"
)
val dependencies = new {
val macwireVersion = "2.3.0"
val reactiveMongoVersion = "0.13.0-play26"
val slickVersion = "3.0.3"
val postgresVersion = "42.2.2"
val scalatestPlayVersion = "3.1.2"
val macwire = "com.softwaremill.macwire" %% "macros" % macwireVersion % "provided"
val reactivemongo = "org.reactivemongo" %% "play2-reactivemongo" % reactiveMongoVersion
val slick = "com.typesafe.play" %% "play-slick" % slickVersion
val slickEvolutions = "com.typesafe.play" %% "play-slick-evolutions" % slickVersion
val postgresql = "org.postgresql" % "postgresql" % postgresVersion
val scalatestPlay = "org.scalatestplus.play" %% "scalatestplus-play" % scalatestPlayVersion % Test
}
lazy val commonDependencies = Seq(
dependencies.macwire,
dependencies.reactivemongo,
dependencies.slick,
dependencies.slickEvolutions,
dependencies.postgresql,
dependencies.scalatestPlay
)
}
# build.sbt
lazy val core = (project in file("modules/core"))
.enablePlugins(PlayScala)
.settings(
name := "app-core",
libraryDependencies ++= Common.commonDependencies ++ Seq(
),
Common.settings
)
lazy val cms = (project in file("modules/cms"))
.enablePlugins(PlayScala)
.settings(
name := "app-cms",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val api = (project in file("modules/api"))
.enablePlugins(PlayScala)
.settings(
name := "app-api",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val reporting = (project in file("modules/reporting"))
.enablePlugins(PlayScala)
.settings(
name := "app-reporting",
libraryDependencies ++= Common.commonDependencies,
Common.settings
)
.dependsOn(core % "test->test;compile->compile")
.aggregate(core)
lazy val backend = (project in file("."))
.enablePlugins(PlayScala)
.settings(
name := "app-backend",
libraryDependencies ++= Common.commonDependencies
)
.dependsOn(
core % "test->test;compile->compile",
cms,
api,
reporting
)
.aggregate(cms, api, reporting)
我无法在核心模块中为我的模型用户添加隐式 Json 格式。
对于后端应用程序,我可以导入 w/o 问题,我在子模块部分缺少什么吗?
谢谢,
仔细检查您是否真的导入了 play-json
库,因为在 Play 2.6 中它是一个独立的库:
libraryDependencies += "com.typesafe.play" %% "play-json" % playVersion