Play子项目无法在IntelliJ上导入Play-json类

时间:2018-05-04 04:05:34

标签: scala intellij-idea sbt playframework-2.6

然而,我已将我的应用拆分为子项目,以便更好地进行组织。我的核心子模块即播放应用无法导入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)

我无法在核心模块中为My model User添加隐式Json格式。

对于后端应用程序,我可以导入w / o问题,在子模块部分中是否有我遗漏的内容?

谢谢,

1 个答案:

答案 0 :(得分:1)

仔细检查您是否实际导入play-json库,因为在Play 2.6中它是一个独立的库:

libraryDependencies += "com.typesafe.play" %% "play-json" % playVersion