You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ中Play子项目无法导入Play-json类问题求助

Fixing play.api.libs.json.Json Import Issue in Play Core Submodule

It looks like your core submodule is missing the Play JSON dependency, which is why you can't import play.api.libs.json.Json. Here's how to fix this step by step:

1. Add Play JSON to Your Common Dependencies

First, update your project/Common.scala to include the Play JSON dependency definition. Make sure the version matches your Play framework version (since you're using 0.13.0-play26 for ReactiveMongo, stick with Play 2.6.x versions):

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" // Example version matching Play 2.6
    // Add Play JSON dependency
    val playJsonVersion = "2.6.15"
    val playJson = "com.typesafe.play" %% "play-json" % playJsonVersion
  }
}

2. Include the Dependency in Your Core Subproject

Next, modify your main build.sbt to add the Play JSON dependency to your core submodule. Assuming your core subproject is defined like this:

lazy val core = (project in file("core"))
 .settings(Common.settings)
 .settings(
    libraryDependencies ++= Seq(
      Common.dependencies.playJson,
      // Add other dependencies your core module needs here
      Common.dependencies.macwire,
      Common.dependencies.slick
    )
  )

3. Verify Compatibility and Refresh

  • Double-check that the Play JSON version you chose is compatible with Scala 2.12.5 (Play 2.6.x fully supports Scala 2.12).
  • Run sbt clean compile in your terminal to rebuild the project, or refresh the project in your IDE to pick up the new dependencies.

Why This Works

The Play JSON library is a standalone artifact separate from the full Play framework. Even if your core module isn't a complete Play application, you can still include just the JSON parsing functionality by adding this specific dependency.

内容的提问来源于stack exchange,提问作者raul782

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:57:12